[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Alternative to variable in template match

Subject: RE: Alternative to variable in template match
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 17 Jan 2002 23:35:21 -0000
alternative of variable in xsl
> 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

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.