This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Alternative to variable in template match


> I wrote a small xsl to copy the nodes below a specified XPATH
> expression
> into new files. I wanted to eventually pass the XPATH in via a command
> line.

XSLT doesn't allow evaluation of XPath expressions unless they are available
at compile time. There's no way of evaluating an XPath expression contained
in a string. Some products (e.g. Saxon and Xalan) have an xx:evaluate()
extension to do this. The only workaround (apart from extension functions)
is to generate or modify the stylesheet before use.

Mike Kay

>
> Since a variable can't be used in 'template match="$path"'
> there must be
> another efficient way to do this. Currently, my work around doesn't
> compare the XPATH expression to the node successfully. Any hints?
>
>
> xsl:
> ----
> <xsl:stylesheet version="1.1"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:output method="xml"/>
>
> <xsl:variable name="dir" select="'out'" />
> <xsl:variable name="prefix" select="'name'" />
> <xsl:variable name="suffix" select="'xml'" />
> <xsl:variable name="xpath"  select="a"/>
>
>
> <xsl:template match="*">
>
> <xsl:if test="$xpath" >
>         <xsl:variable name="filename" select="concat($dir,'/',$prefix,
> position(),'.',$suffix)"/>
>
>         <xsl:document href="{$filename}">
>         <doc>
>                 <xsl:copy-of select="node()"/>
>         </doc>
>         </xsl:document>
>
> </xsl:if>
>
> </xsl:template>
> </xsl:stylesheet>
>
>
> ----
>
> xml:
> ----
> <doc>
> <a>
> <b>
> <c>This is 1</c>
> </b>
> </a>
>
> <a>
> <b>
> <c>This is 2</c>
> </b>
> </a>
>
> <a>
> <b>
> <c>This is 3</c>
> </b>
> </a>
>
> </doc>
>
>
> ----
>
>
>
> Thanks,
> --Rick Anderson
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]