Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2006, 11:39 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Apply a propertie file to a different xml file

Hi folks,
I want to write a XSLT gets properties e.g. XPath-Expression from one file and apply it to a different one. I tried this:
Code:
<rule>

  <xpath attribute1="p1" attribute2="p1_"/>
  <xpath attribute1="p2" attribute2="p2_"/>
</rule>
Code:
<test>
  <p1/>
  <p2/>
  <p3/>
</test>
Code:
<test>
  <p1_/>
  <p2_/>
  <p3/>
</test>
Code:
<xsl:param name="document" select="document('XMLfile.xml')"/>
<xsl:template match="/rule//xpath">
  <xsl:apply-templates select="$document" mode="document_">
    <xsl:with-param name="attribute1" select="./@attribute1" tunnel="yes"/>
    <xsl:with-param name="attribute2" select="./@attribute2" tunnel="yes"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="/" mode="document_">
  <xsl:param name="attribute1"/>
  xsl:apply-templates select="$attribute1" mode="tag_"/>
</xsl:template>

<xsl:template match="p1" mode="tag_">
  <xsl:param name="attribute2"/>
  <xsl:element name="{$attribute2}"/>
</xsl:template>
The code is not complete, but I failure to apply the p1-template. Could anybody help me?[u]</u>[u]</u>[u]</u>[u]</u>
Thanks a lot.
Clyne

 
Old December 30th, 2006, 06:26 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's no standard way in XSLT of constructing an XPath expression at run-time (or reading it from a file at run-time) and then evaluating it. Several products have extension functions to do this (e.g. saxon:evaluate() in Saxon). Alternatively, consider using XSLT to construct a stylesheet that incorporates the XPath expressions, and then executing that stylesheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 30th, 2006, 09:44 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael. I used the extension function but it doesn't work:
Code:
...
<xsl:apply-templates select="$document" mode="document_">
  <xsl:with-param name="attribute1" select="./@attribute1" tunnel="yes"/>
</xsl:apply-templates>
...
<xsl:template match="/" mode="document_">
  <xsl:param name="attribute1" select="default"/>
  <xsl:variable name="test" select="concat('/*//',$attribute1)"/>
  <xsl:value-of select="$attribute1"/>
  <xsl:apply-templates select="saxon:evaluate($test)" mode="tag_"/>
</xsl:template>
The value-of select gives the values of with-param back and overwrite default respectively. But in saxon:evaluate(..) I get an exception: Static error in XPath expression supplied to saxon:evaluate: XPath syntax error at char 4 in {/*//}: Unexpected token "<eof>" in path expression. Did I overlook a fault? Thanks at forward.

 
Old December 31st, 2006, 11:17 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The argument supplied to saxon:evaluate() must be a valid XPath expression. "/*//" is not a valid XPath expression.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 31st, 2006, 11:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Looking more deeply, $attribute1 is taking its default value of "", because the supplied parameter said tunnel="yes" and the xsl:param declaration implies tunnel="no".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 2nd, 2007, 10:56 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael. The point with the 'tunnel'-Attribute I did not see.






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to apply CSS to XSLT file??? rakesh XSLT 1 July 25th, 2008 03:20 AM
Help with PHP file reading XML file for output rydog65 Beginning PHP 0 March 26th, 2008 05:13 PM
Apply changes to more than one file bcogney XML 11 March 6th, 2007 07:02 PM
Input type=file apply a filter?? italiansensation ASP.NET 1.x and 2.0 Application Design 3 May 24th, 2006 04:06 AM
Apply Custom template & import data from text file shampabera Excel VBA 2 August 8th, 2005 07:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.