Subject: RE: [xsl] Alternative to variable in template match From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Thu, 17 Jan 2002 23:35:21 -0000 |
> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Alternative to variable i, G. Ken Holman | Thread | [xsl] Get an element with max. numb, Xiaocun Xu |
[xsl] Converting logical <em>s to p, Michael Stillwell | Date | RE: [xsl] Re: RE: Higher-Order Func, Michael Kay |
Month |