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

FW: How to navigate the tree from a selected node to t

Subject: FW: How to navigate the tree from a selected node to the root?
From: "Nirmala R" <nirmala.r@xxxxxxxxxx>
Date: Tue, 22 Oct 2002 09:02:25 +0530
xsl navigate output tree
Hi,

Can anyone tell me how can I get the following output?
Please refer the below mail.

Thanks in advance and regards,
Nirmala

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Nirmala R
Sent: Saturday, October 19, 2002 5:01 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  How to navigate the tree from a selected node to the
root?


Hi,

Thank you very much for the answer.
That answers my question. Thank you very much.

I need a little enhancement.

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="try.xsl"?>

<books>
<book name="name2">
	<otherdetails price="10"/>
	<otherdetails price="25"/> <!-- Newly added -->
</book>

<book name="name1">
	<otherdetails price="20"/>
	<otherdetails price="35"/> <!-- Newly added -->
</book>
</books>

Now applying the stylesheet as you have mentioned, I get the output as

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="try.xsl"?>
<books>
  <book name="name2">
        <otherdetails price="10"/>
        <otherdetails price="25"/>
</book>
</books>

My requirement is that I want to get

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="try.xsl"?>
<books>
  <book name="name2">
        <otherdetails price="10"/>
</book>
</books>

The sibling of otherdetails also should not be selected.

Hence I tried the stylesheet like

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"/>

<xsl:template match="books">
    <xsl:copy>
      <xsl:apply-templates select="@* | book[otherdetails/@price = '10']" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
	<xsl:if test="node()/otherdetails/@price='10'">   <!-- I know, this is not
correct, but i need something like this -->
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
	</xsl:if>
  </xsl:template>

</xsl:stylesheet>

Basically, I should be able to differentiate within the template
match="@*|node(), whether
it is an attribute or a book node. If it is a book node and if
otherdetails/@price is not 10,
then that should not be included in the output xml.

Can you please tell me how could I do that?

Thanks in advance,
Best Regards,
Nirmala



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
Jarno.Elovirta@xxxxxxxxx
Sent: Friday, October 18, 2002 5:28 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  How to navigate the tree from a selected node to the
root?


Hi,

> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="try.xsl"?>
>
> <books>
> <book name="name2">
> 	<otherdetails price="10"/>
> </book>
>
> <book name="name1">
> 	<otherdetails price="20"/>
> </book>
> </books>
>
> and an xsl for the above as:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="xml"/>
>
> 	<xsl:template match="/">
> 	<xsl:for-each select="books/book/otherdetails[@price='10']">
> 	<xsl:copy-of select="parent::*"/>
> 	</xsl:for-each>
>
> 	</xsl:template>
> </xsl:stylesheet>
>
> This gives the output as:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <book name="name2">
>         <otherdetails price="10"/>
> </book>
>
> I want to get like this:
> <books>
> <book name="name2">
>         <otherdetails price="10"/>
> </book>
> </books>
>
> i.e. From this paricular selected node, i want to navigate
> till the root
> node and get the output.
> I will not know how many more ancestors are there to reach
> the root node.
>
> Can you please help me out for doing the same.

Will changing the approach to

  <xsl:template match="books">
    <xsl:copy>
      <xsl:apply-templates select="@* | book[otherdetails/@price = '10']" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

be a suitable solution?

Cheers,

Jarno

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.