|
|
 |
| 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.
|
 |

July 9th, 2009, 06:22 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
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...
|

July 9th, 2009, 08:12 PM
|
 |
Wrox Author
Points: 12,642, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 Posts
|
|
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
|

July 9th, 2009, 08:17 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by mhkay
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...
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |