ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Stirling" <>
Subject [offtopic] RE: Generating relative paths with XSLT
Date Sun, 17 Nov 2002 21:59:25 GMT
Hi Frank,

Yes, that's much clearer.  There are at least a couple XSL ways to do it
I can think of.  Maybe someone else knows a better way.

One idea is to set the depth of the XML page in an attribute of the
<page/> element (like <page depth='1' title='special offers'>) and use
its value in an <xsl:choose/> or other flow control construct to output
the appropriate number of "../" (if any) in img src="".

Similar, but better, would be to set the relative path to the root
images dir (and possibly other stuff, like include files or css) like
<page path2root='../../' title='special offers'> and use <xsl:variable/>
in the XSL to get that and set an imageDir variable:

<xsl:variable name="imageDir"><xsl:value-of

And output it in place when needed:

<img border="0">
  <xsl:attribute name="src"><xsl:value-of

Scott Stirling

> -----Original Message-----
> From: Frank Carver [] 
> Scott Stirling <> said:
> > Please explain what you mean.  Do you get errors during 
> > transformation? Not sure what the real problem is.  How 
> exactly do the 
> > relative hrefs in the input XML differ from the output HTML?
> Ah.  Sorry for the confusion.  My input documents have no 
> references, relative or otherwise.  The references are part 
> of the style, and described in the stylesheet.  Here's a 
> simplified example:
> file ./index.xml:
>   <page title='home page'>
>   <p>Welcome to my statically-styled web site!</p>
>   <p>See our <a href='products/special.html">Special Offer</a></p>
>   </page>
> file products/special.xml:
>   <page title='special offers'>
>   <p><b>Today Only!</b> Widgets at $39/kg</p>
>   </page>
> I wish to apply the same stylesheet to both these pages (and 
> lots of others, of course).  Something like:
> file default.xsl: (trimmed a lot from the real one, and not 
> syntax checked!)
>   <?xml version="1.0"?>
>   <xsl:stylesheet 
> xmlns:xsl="" version="1.0">
>   <xsl:output method="html" encoding="8859-1"/>
>   <xsl:template match="page">
>   <html><head><title><xsl:value-of 
> select="@title"/></title></head><body>
>   <h2><img src='images/logo.gif'/> <xsl:value-of 
> select="@title"/></h2>
>   <xsl:apply-templates select="node()"/>
>   </body></html>
>   </xsl:template>
>   <xsl:template match="@*|node()|processing-instruction()|comment()">
>    <xsl:copy>
>     <xsl:apply-templates 
> select="@*|node()|processing-instruction()|comment()"/>
>    </xsl:copy>
>   </xsl:template>
>   </xsl:stylesheet>
> The problem occurs with the reference to images/logo.gif.  It 
> works fine for pages at the "top level" (such as index.html, 
> above).  But pages in subdirectories (such as 
> products/special.xml, above) would really need to generate 
> something like "../images/logo.gif".
> Is that clearer ?
> Thanks for your interest.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message