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

Re: relative path from one node to another (XSLT 2.0

Subject: Re: relative path from one node to another (XSLT 2.0 solution)
From: "Richard Lewis" <richardlewis@xxxxxxxxxxxxxx>
Date: Fri, 20 May 2005 11:44:04 +0100
document relative path
On Fri, 20 May 2005 09:19:52 +0100, "Richard Lewis"
<richardlewis@xxxxxxxxxxxxxx> said:
> I wonder if you'd had any thoughts on the problem I described of
> implementing a mechanism for linking from one output document to another
> using a
> <link section="tom">See Tom's page</link>
> element in the source tree?
> 
> Such an element should transformed to an HTML <a> tag with the correct
> 'href' attribute to link from the output document in which it occurs to
> the output document for the section with id 'tom'.
> 
OK, I've managed to work out a solution:

First thing I did was to give the document (root) node an id attribute
(id="ROOT") to make it behave a bit more like a section (polymorphism!).
Then I made a named template which takes the id values of two sections
(one may be 'ROOT') and returns the file system path between them:

<xsl:template name="relative-fs-path">
  <xsl:param name="from-id" />
  <xsl:param name="to-id" />

  <xsl:for-each select="//*[@id=$from-id]/ancestor::*[(name()='section'
  or name()='document') and (@display='page')]">
    <xsl:if test="@id!='ROOT'">../</xsl:if>
  </xsl:for-each>
  <xsl:for-each
  select="//*[@id=$to-id]/ancestor-or-self::*[(name()='section' or
  name()='document') and (@display='page')]">
    <xsl:if test="@id!='ROOT' and position()!=last()"><xsl:value-of
    select="@id" />/</xsl:if>
  </xsl:for-each>
</xsl:template>

This generates non-relative paths; e.g. the path from tom.html to
harry.html (see beginning of thread) instead of being simply
"harry.html" is "../../staff/permanent/harry.html".

I use this for getting the file names for xsl:result-document, for
getting the correct path to link from section to another and for the
paths to the images directories and from the site's main menu to the
section documents.

I don't expect this is an ideal solution, but it works. Any comments
would be welcome!

Cheers,
Richard

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.