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 June 6th, 2007, 02:54 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default tunneling parameters

Considering the following XSLT:

<xsl:template match="/">
  <xsl:variable name="test" select="true()"/>
  <xsl:choose>
    <xsl:when test="$test">
     <xsl:apply-templates>
       <xsl:with-param name="modify" select="$test"/>
     </xsl:apply-templates>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="list">
  <xsl:param name="modify" />
  <xsl:copy>
   <xsl:if test="$modify">
    do something
   </xsl:if>
  </xsl:copy>
</xsl:template>


The XML:

<document>
  <lists>
    <list>foo</list>
    <list>bar</list>
  </lists>
</document>

For some reason, the parameter is not being passed on to the other templates.

 
Old June 6th, 2007, 03:28 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your template for match="/" applies templates to the children of "/", specifically to the <document> element. There's no explicit template for the <document> element so the default template gets invoked. In XSLT 1.0 this does

<xsl:template match="document">
  <xsl:apply-templates/>
</xsl:template>

It doesn't do:

<xsl:template match="document">
  <xsl:param name="modify"/>
  <xsl:apply-templates>
    <xsl:with-param name="modify" select="$modify"/>
  </xsl:apply-templates>
</xsl:template>

This catches quite a few people out, so the spec has been changed in XSLT 2.0 - in 2.0 the built-in templates do pass parameters through.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 6th, 2007, 03:45 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sorry, should have provided more information. I am using XSLT 2.0 and saxon8. I was under the impression that 2.0 supports the passing down of parameters through built in template rules.

 
Old June 6th, 2007, 05:11 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It works for me. This is the output I get:

<?xml version="1.0" encoding="UTF-8"?>

    <list>
    do something
   </list>
    <list>
    do something
   </list>


That's with 8.9.0.3

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameters dcct84 C# 6 September 27th, 2007 05:26 PM
parameters dpkbahuguna ASP.NET 1.x and 2.0 Application Design 0 April 3rd, 2007 07:27 AM
Parameters Dharam80 Access 3 August 19th, 2005 01:59 PM





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