p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 9th, 2009, 06:22 PM
Authorized User
Points: 75, Level: 1
Points: 75, Level: 1 Points: 75, Level: 1 Points: 75, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default XSLT for XML to Text

Hi Guys,

Need your help on following....

I have following XML which i want to covert it as Text with Numbering added to it.

Code:

<?xml version="1.0"?>
<ROWSET>
<ROW>
<ERROR_MESSAGE>Error</ERROR_MESSAGE>
</ROW>
<ROW>
<ERROR_MESSAGE>Error</ERROR_MESSAGE>
</ROW>
<ROW>
<ERROR_MESSAGE>Error</ERROR_MESSAGE>
</ROW>
</ROWSET>
XSLT code

Code:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="ROWSET">
<xsl:apply-templates select="ROW"/>
</xsl:template>
<xsl:variable name="ItemIndex" select="0"/>
<xsl:template match="ROW">
<xsl:for-each select="*">
<xsl:variable name="pos" select="position()"/><xsl:value-of select="$ItemIndex[$pos]"/>
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>

Using XSLT on above XML ...i am getting following output...

0Error
0Error
0Error

desired output...
1Error
2Error
3Error

thanks in advance for pointing out the error in my XSLT...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 9th, 2009, 08:12 PM
mhkay's Avatar
Wrox Author
Points: 12,642, Level: 48
Points: 12,642, Level: 48 Points: 12,642, Level: 48 Points: 12,642, Level: 48
Activity: 97%
Activity: 97% Activity: 97% Activity: 97%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 Posts
Default

Well, each ROW has one element child, so the for-each select="*" selects one node, and the position of that node is always 1. So $pos is always 1. $ItemIndex is a sequence of integers of length 1 (specifically, a singleton integer whose value is zero), so $ItemIndex[$pos] is the first integer in this sequence, which is zero. I've no idea what you had in mind when you wrote this code.

Try:

Code:
<xsl:template match="ROW">
  <xsl:number/>
  <xsl:value-of select="ERROR_MESSAGE"/>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 9th, 2009, 08:17 PM
Authorized User
Points: 75, Level: 1
Points: 75, Level: 1 Points: 75, Level: 1 Points: 75, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
Well, each ROW has one element child, so the for-each select="*" selects one node, and the position of that node is always 1. So $pos is always 1. $ItemIndex is a sequence of integers of length 1 (specifically, a singleton integer whose value is zero), so $ItemIndex[$pos] is the first integer in this sequence, which is zero. I've no idea what you had in mind when you wrote this code.

Try:

Code:
<xsl:template match="ROW">
  <xsl:number/>
  <xsl:value-of select="ERROR_MESSAGE"/>
</xsl:template>
Thanks mhkay..newbie to coming to begginer level...overthinking ....so i did that mistake....your solution worked perfactly...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
Can 1 xslt transform an xml doc into 2 text files Raju Sarode XSLT 7 November 3rd, 2006 04:10 PM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 02:58 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 09:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM



All times are GMT -4. The time now is 03:22 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc