p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Element (http://p2p.wrox.com/showthread.php?t=43903)

Neal June 13th, 2006 03:38 AM

Element
 
Hi,

The following is the XML that I need to transform (Input):

Code:

<Anal Type="PGRP">
<Seg No="1" Code="1">FEED</Seg>
 <Seg No="2" Code="1D">ANIMAL</Seg>
 <Seg No="3" Code="DC">FIN</Seg>
</Anal>

The following format is my required Output:

Code:

<Reference Type="Class Code" AssignedBy="Manufacturer" Explanation="Feed">1</Reference>
I have coded the following lines which retrieves the value '1', but how do I retrieve the value 'Feed' (See **** in code below)?

Code:

<xsl:template name="Anal" match="*[@Type='PGRP']">
<xsl:for-each select=".//*[@Type='PGRP']/Seg/@No">
<xsl:if test="position() =1">
<xsl:element name="Reference">
    <xsl:attribute name="Type">Major Class Code</xsl:attribute>
     <xsl:attribute name="AssignedBy">Manufacturer</xsl:attribute>
     <xsl:attribute name="Explanation">****</xsl:attribute>   
     <xsl:value-of select="current()"/>   
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>

The above code produces the following (current) Output:

Code:

<Reference Type="Major Class Code" AssignedBy="Manufacturer" Explanation="">1</Reference>
Question
How do I retreive the 'Feed' value in my code (to be positioned after 'Explanation=')?

Thanks in advance,


Neal

A Northern Soul

mhkay June 13th, 2006 03:57 AM

You could start with <xsl:value-of select="Seg". If you really need to do the case conversion, it's something like

concat(substring(Seg,1,1), translate(substring(Seg,2), 'ABCDE...', 'abcde...')))

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


All times are GMT -4. The time now is 07:25 AM.

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