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

Stange behavior with parameters, can somebody explain?

Subject: Stange behavior with parameters, can somebody explain?
From: Gunther Schadow <gunther@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Jan 2002 02:45:16 -0500
stange
Help! I'm ripping my heair out on this one. Please explain
why the effect of with-param in apply-templates select='expr'
depends on whether expr is an xpath selector on the current
document or a synthesized node-set.

This is my XML file:

<ROOT><FOO/><BAR/></ROOT>

And this is the common part of an XSLT:

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  exclude-result-prefixes="exsl">
<!-- For MSXSL use this instead
  xmlns:exsl="urn:schemas-microsoft-com:xslt"
-->

<xsl:output method='xml' encoding="iso-8859-1" indent='yes'/>

<xsl:template match="ROOT">
  <xsl:copy>
    <xsl:apply-templates select='child::node()[1]'/>
  </xsl:copy>
</xsl:template>

<xsl:template match="BAR">
  <xsl:param name='P'/>
  <BAR P='{$P}'/>
</xsl:template>

<!-- variant here -->

</xsl:stylesheet>


Now I show you two variants of templates to deal with the FOO element. The first one uses the xpath selector:

<xsl:template match="FOO">
  <FOO/>
  <xsl:apply-templates select='following-sibling::node()[1]'>
    <xsl:with-param name='P' select="'V'"/>
  </xsl:apply-templates>
</xsl:template>

when I run the transform, the result is:

<?xml version="1.0" encoding="iso-8859-1"?>
<ROOT>
   <FOO/>
   <BAR P="V"/>
</ROOT>

as it should be. However, when I use this variant:

<xsl:template match="FOO">
  <FOO/>
  <xsl:variable name='SYNTH'>
    <BAR/>
  </xsl:variable>
  <xsl:apply-templates select='exsl:node-set($SYNTH)'>
    <xsl:with-param name='P' select="'V'"/>
  </xsl:apply-templates>
</xsl:template>

the result is

<?xml version="1.0" encoding="iso-8859-1"?>
<ROOT>
   <FOO/>
   <BAR P=""/>
</ROOT>

as you see, here the parameter P <= V was not carried into the
applied templates. Why is that?

I tried with both saxon and msxml and they both do the same
thing.

Whatever it is, it is very obscure and makes my life very
difficult.

Of course you don't see the use case from this dummed down
example. My use case is string parsing for 'up-translation'
where I match a head of a string then clip off the head
and apply the templates on the rest of the text node. I
cannot pass any parameters through this kind of process,
ouch!

regards
-Gunther


PS: workaround seems to be to wrap the rest of the text node in an element with parameters as attributes or something. Argh!

--
Gunther Schadow, M.D., Ph.D.                    gschadow@xxxxxxxxxxxxxxx
Medical Information Scientist      Regenstrief Institute for Health Care
Adjunct Assistant Professor        Indiana University School of Medicine
tel:1(317)630-7960                         http://aurora.regenstrief.org



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.