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

RE: Generating an Xpath expression dynamically

Subject: RE: Generating an Xpath expression dynamically
From: "Morgan, Corey" <CMorgan@xxxxxxxxx>
Date: Tue, 21 Oct 2003 10:50:36 -0600
corey morgan
Hello.

> I am trying to use XSLT to transform a set of XML files, each type with
> its own set of nodes, into a legacy file format. It is best if the XSLT
> was generic. I've tried to reference a second XML file that contains the
> transformation rules. This second XML file contains the relative XPath
> expression for each element in the source XML file and the target location
> in the legacy file format. I get the relative XPath string from the second
> XML file into a parameter, but when I try to use that parameter in a XSLT
> value-of element, it outputs the relative XPath string rather than the
> contents of that node in the source XML file.
> 
> Does anyone know how to output the contents of an element node in a source
> XML file using a XPath string read in from another XML file?
> Thanks.

An example may help.

If you're thinking of performing some kind of dynamic matches in your
stylesheet, you'll be disappointed. 
For example, the following will not work:

  <?xml version="1.0"?>
  <xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:variable name="dyn-xpath" select="'this/is[@nuts]'"/>
    <xsl:template match="$dyn-xpath">
       No good.
    </xsl:template>   
  </xsl:stylesheet>

You'll get the error: "Variables may not be used within this expression",
or some such.

Consider the following:

You have a "second XML file [that] contains the relative XPath expression 
for each element in the source XML file and the target location in the 
legacy file format".

But you know, that almost smells like XSL!  I don't know the origin of this
"second XML file", but you might consider converting that file into a 
stylesheet, and avoid the middleman.

If you can't/won't touch this second XML file, and/or you want to be a
bit trickier, why not _generate_ your XSL stylesheet from it.
After all, XSL _is_ XML, not merely to add verbosity to your life, but also 
so that it may be generated from some other stylesheet.

Hope this helps.

Corey Morgan

 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.