Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xslt / xpath issue

Status
Not open for further replies.

chrisd33

Technical User
Aug 22, 2005
6
GB
hi

i wish to transform from xml to xml and i'm using the following to code to output to each instance of the element



code:
--------------------------------------------------------------------------------

<age> <xsl:attribute name="range"> <xsl:for-each select="users/user"> <xsl:value-of select="age_x0020_range"/> </xsl:for-each> </xsl:attribute> </age>

--------------------------------------------------------------------------------



the problem is its outputting everything within the same tags like so, so that its repeating the value within the same element and not creating lots of seperate elements, each with their own value.





code:
--------------------------------------------------------------------------------

<age range="TEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEETEE/>

--------------------------------------------------------------------------------



what is the xpath error i'm making ?

cheers

chris
 
thanks.

here is the xslt

<?xml version='1.0' encoding='us-ascii' ?>
<xsl:stylesheet version="1.0" xmlns:xsl=" <xsl:eek:utput method="xml"/>
<xsl:template match="/">
<identities>
<users>
<user>
<xsl:attribute name="firstname">
<xsl:value-of select="users/user/firstname"/>
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="users/user/@id"/>
</xsl:attribute>
<xsl:attribute name="lastname">
<xsl:value-of select="users/user/lastname"/>
<level>
<xsl:attribute name="name">
<xsl:value-of select="users/user/level_x0020_name"/>
</xsl:attribute>
</level>
<xsl:for-each select="users/user">
<age>
<xsl:attribute name="range">
<xsl:value-of select="age_x0020_range"/>
</xsl:attribute>
</age>
</xsl:for-each>
</user>
</users>
</identities>

</xsl:template>
</xsl:stylesheet>


and here is a desired output document

<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE identities SYSTEM "identifiertransfer-v101.dtd">
<identities version="001" editdate="20050727" customer-id="Magna" completedata="TRUE">
<users>
<user id="94101" firstname="Serge" lastname="Buchner" ><level name="UPP"/><age range="AUT"/></user>

<user id="94102" firstname="Igor" lastname="Smart" ><level name="UPP"/><age range="AUT"/></user>

</users>


</identities>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top