|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








