This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Stange behavior with parameters, can somebody explain?


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@regenstrief.org
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]