[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: JBryant@xxxxxxxxx
Date: Thu, 19 May 2005 14:16:51 -0500
xslt node path
Hi, Richard,

I did it this way:

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

  <!-- process the root -->
  <xsl:template match="document">
    <xsl:result-document href="root/delete.me"/>
    <xsl:apply-templates>
      <xsl:with-param name="path" select="'root'"/>
    </xsl:apply-templates>
  </xsl:template>

  <!-- process the directories -->
  <xsl:template match="section[section/@display='page']">
    <xsl:param name="path"/>
    <xsl:result-document href="{concat($path, '/', @id, '/delete.me')}"/>
    <xsl:apply-templates>
      <xsl:with-param name="path" select="concat($path, '/', @id)"/>
    </xsl:apply-templates>
  </xsl:template>

  <!-- process the pages -->
  <xsl:template 
match="section[@display='page'][not(section/@display='page')]">
    <xsl:param name="path"/>
    <xsl:result-document href="{concat($path, '/', @id, '.xml')}">
      <chunks>
        <xsl:apply-templates/>
      </chunks>
    </xsl:result-document>
  </xsl:template>

  <!-- process the inline sections -->
  <xsl:template match="section[@display='inline']">
    <content chunk="{@id}"/>
  </xsl:template>

</xsl:stylesheet>

Note that the "delete.me" bit is in there because I couldn't quickly 
figure out how to get result-document to make just a directory. Perhaps 
folks who have more file-system experience (or more time to fiddle) can 
help there.

Also, I relied on the fact that, in the data you presented, directories 
always had child sections with display="page" attributes. You'll have to 
tinker with the algorithm a bit if that's not true in your production 
system.

Anyway, when I applied this stylesheet to your data, I got the desired 
output, except that I got no temporary directory because your data didn't 
specify one. I did get a file called staff/permanent.xml, though. Perhaps 
you have a small error from copying earlier chunks into your sample. I 
didn't create actual HTML files, so I just called them XML files. I'm sure 
you can adjust when you fill out the details.

Interesting problem, by the way.

Tested with Saxon 8.4.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

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.