Wrox Programmer Forums
|
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 June 13th, 2006, 03:38 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default 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
__________________
Neal

A Northern Soul
 
Old June 13th, 2006, 03:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
translate element name to element name lexzeus XSLT 3 September 4th, 2006 09:04 AM
Finding the last element jeremycod XSLT 4 March 12th, 2006 05:45 PM
Can I tell what element I am currently in? insanek XSLT 4 September 19th, 2005 05:44 AM
adding of element and assigning to one element sushovandatta XSLT 2 November 16th, 2004 07:04 PM





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