[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Still, XSLT is great, I love it more each day.
-Gunther
Gunther Schadow wrote:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] Stange behavior with parameters, can somebody explain?
Subject: Re: [xsl] Stange behavior with parameters, can somebody explain? From: Gunther Schadow <gunther@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 17 Jan 2002 13:37:52 -0500 |
Oops, first the message was rejected and now it went through twice. Sorry for that.
Thanks so much for the hint. Heck, I was fiddling with the default rule for 'node()' but forgot about the root node. This turns out to be a mistake similarly easy to make and obscure to discover as the famous if(a = 0) fallacy in C.
Last night I rewrote all my parameter passing to use a synthesized node structure only to loose sleep over it and now turn it all back. Ah well. But I'm happy it was my mistake.
Still, XSLT is great, I love it more each day.
-Gunther
Gunther Schadow wrote:
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Stange behavior with para, Michael Kay | Thread | [xsl] Stange behavior with paramete, Gunther Schadow |
Re: [xsl] Quark IV, David Carlisle | Date | [xsl] Re: RE: Higher-Order Function, Dimitre Novatchev |
Month |