[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Still thinking to object oriented...

Subject: Re: Still thinking to object oriented...
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 24 Sep 2008 14:27:08 +0530
Re:  Still thinking to object oriented...
You can leverage some of the XSLT 2.0 facilities for this. Below is a
stylesheet which works ...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:xs="http://www.w3.org/2001/XMLSchema"
                        version="2.0">

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

  <xsl:template match="/">
    <xsl:variable name="temp" as="xs:string*">
       <xsl:for-each select="//*[contains(name(), 'special_node')]">
          <xsl:for-each select="ancestor-or-self::*">
             <xsl:value-of select="name()" />
          </xsl:for-each>
       </xsl:for-each>
    </xsl:variable>
    <xsl:for-each select="distinct-values($temp)">
      <xsl:value-of select="." />
      <xsl:text>&#xa;</xsl:text>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>


On Wed, Sep 24, 2008 at 12:35 PM, Jonas Bassl
<jonas.bassl@xxxxxxxxxxxxxx> wrote:
> Hallo,
>
> i have a problem to solve in XSLT and i just need help with the
> processing of that language. I have an XML-tree as follows:
>
> [CODE]
> <node1>
>  <node2>
>     <node3>
>         <special_node1/>
>     </node3>
>     <node4>
>         <node5>
>             <node6>
>                 <special_node2/>
>             </node6>
>         </node5>
>     </node4>
>  </node2>
> </node1>
> [/CODE]
>
> What i have to do is, to search for every "special_node*" for printing
> out the name and potential attributes of that node and all his
> parents. This is quite easy to get. I do it like this:
>
> [CODE]
> <xsl:stylesheet version="2.0"
> ...
>  <xsl:template match="//*">
>     <xsl:for-each select="//*">
>         <xsl:variable name="current_name" select="name(.)"/>
>         <xsl:if test="contains(string($current_name),'Special')">
>             <xsl:for-each select="ancestor-or-self::node()">
>                 <xsl:value-of select="name()"></xsl:value-of>
>             </xsl:for-each>
>         </xsl:if>
>     </xsl:for-each>
>  </xsl:template>
> </xsl:stylesheet>
> [/CODE]
>
> My problem now is, that i don't want one node to appear twice in the
> result list.
> For example in the code above, the result would be something like:
>
> node1
> node2
> node3
> special_node1
> node1
> node2
> node4
> node5
> node6
> special_node2
>
> You see that "node1" and "node2" appear twice which is right after the
> style sheet i wrote there.
> Can anyone help me now to change the style sheet that the following
> result would be created:
>
> node1
> node2
> node3
> special_node1
> node4
> node5
> node6
> special_node2
>
> Needles to say, that this example is by far not as complicated as the
> real XML-structures, i have to process, but i hope, you will
> understand the main problem. I would be really happy if someone can
> help my here because i am racking my brain now since days.
>
> Regards,
>
> Jonas



-- 
Regards,
Mukul Gandhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.