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 October 3rd, 2009, 07:52 AM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default XSLT output path route

the XML file:
Code:
<?xml .....
<app name="A" path="">
   <app name="B" path="p1">
      <app name="C" path="p2" />
      <app name="D" path="p3" />
   </app>
   <app name="E" path="p4" />
</app>
Then in XSLT file I set with javascript a variable path="p2":
Code:
<xsl:variable name="path" select="'p2'" />
How can I get with XSLT a path route like this:
A :: B :: C <- this is output of XSLT

I am totally confused but I am sure XSLT can do this.
 
Old October 3rd, 2009, 08:00 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You can simply process the ancestor-or-self:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output method="text"/>
  
  <xsl:param name="path" select="'p2'"/>
  
  <xsl:template match="/">
    <xsl:for-each select="//app[@path = $path]/ancestor-or-self::app/@name">
      <xsl:value-of select="."/>
      <xsl:if test="position() != last()"> :: </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
chameleon (October 3rd, 2009)
 
Old October 3rd, 2009, 11:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's even easier in XSLT 2.0:

<xsl:value-of select="//app[@path = $path]/ancestor-or-self::app/@name"
separateor=" :: "/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old October 3rd, 2009, 11:09 AM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Wow!
It works perfect.
I was not aware of ancestor-or-self.
Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT to get hyperlinks in output ashv XSLT 2 December 7th, 2008 06:14 AM
no route found "/\\look\\at" with {:method=>:get} cazalot BOOK: Beginning Ruby on Rails 2 January 3rd, 2008 07:27 AM
Select a path to keep in XSLT lakumc XSLT 7 December 10th, 2007 12:30 PM
XSLT Looks right, but no output Alderian72 XSLT 1 June 9th, 2005 08:47 AM
DNS , Route through, RT nakulmadaan BOOK: Beginning Java 2 2 March 16th, 2005 11:41 AM





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