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 September 16th, 2004, 03:45 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display nodes from xml

Hi,
Please help with this xml and xsl:
---------------------------------------------------------------
<proced>
   <aaa_code V="111">
    <cat>
        <ccc_code V="100"/>
    </cat>
   </aaa_code>
   <aaa_code V="222">
    <cat>
        <ccc_code V="200"/>
        <ccc_code V="100"/>
    </cat>
   </aaa_code>
   <aaa_code V="333">
    <cat>
        <ccc_code V="200"/>
        <ccc_code V="100"/>
    </cat>
   </aaa_code>
</proced>
----------------------------------------------------------------
I want display like this:
--------------------------------
100(ccc_code value)
--------------------------------
    111(aaa_code value)
    222(aaa_code value)
    333(aaa_code value)
------------------------------
200(ccc_code value)
------------------------------
    222(aaa_code value)
    333(aaa_code value)
---------------------------


Here is the XSL I wrote.But this is not displaying 'a_code' node value correctly.
I declared the key on the top:
---------------------------------------------------------------
<xsl:key name="code_duplicate" match="//proced/aaa_code/cat/ccc_code" use="@V"/>

<xsl:for-each select="proced/aaa_code/cat/ccc_code[count(.|key('code_duplicate',@V) [1]) = 1]">
<tr>
   <td>
    <xsl:value-of select="@V"/>
   </td>
</tr>
<tr><td>[u]AAA Code</u></td>
</tr>
    <xsl:for-each select="proced/aaa_code">
       <tr><td>
        <xsl:value-of select="@V"/></td>
       </tr>
    </xsl:for-each>
</xsl:for-each>
----------------------------------------------------------

 
Old September 17th, 2004, 03:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Basically within your outer for-each the context node is ccc_code. To reach the aaa_code node you need the path
Code:
../parent::aaa_code
.
Here's a slightly more refined version that sorts the nodes as well, you may not need that part:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:key name="code_duplicate" match="ccc_code" use="@V" />
  <xsl:template match="proced">
    <xsl:for-each select="aaa_code/cat/ccc_code[count(. | key('code_duplicate', @V)[1]) = 1]">
      <xsl:sort select="@V"/>
      <xsl:value-of select="concat(@V, ' (', name(), ' value)' )"/><xsl:text>#xa;</xsl:text>
      <xsl:for-each select="key('code_duplicate', @V)">
        <xsl:sort select="../parent::aaa_code/@V"/>
        <xsl:variable name="current" select="../parent::aaa_code"/>        
        <xsl:text>#x9;</xsl:text>
        <xsl:value-of select="concat($current/@V, ' (', name($current), ' value)' )"/><xsl:text>#xa;</xsl:text>
      </xsl:for-each>     
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
--

Joe (Co-author Beginning XML, 3rd edition)
 
Old September 17th, 2004, 07:57 AM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello sir..

Thank you so much.It worked fine.I appreciate your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing nodes as they appear in the XML spidergirl1979 XSLT 4 January 21st, 2008 05:50 AM
How can I display parent & child nodes if XML .... vishnu108mishra ASP.NET 2.0 Basics 0 November 17th, 2007 07:45 AM
Recursive nodes in XML Schema XSLTer XML 1 April 13th, 2007 12:25 PM
HOW TO: Display specified # of nodes kwilliams XSLT 2 October 5th, 2005 11:04 AM
How to display all nodes in my Network using VB 6 harini19 VB How-To 1 January 16th, 2004 10:10 AM





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