Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2009, 05:22 PM
Authorized User
 
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...
 
Old July 9th, 2009, 07:12 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old July 9th, 2009, 07:17 PM
Authorized User
 
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...





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 01:58 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.