[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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>
<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
-- 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|