|
[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Possible MSXML 3 / 4 bug: using a for-each on xsl:
Subject: Re: Possible MSXML 3 / 4 bug: using a for-each on xsl:variable/ tree-frag is misbehaving
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 14 May 2002 16:41:19 +0200
|
Hi Jeff,
you only have a RTF, if you construct one, e.g. in a variable as your
example. You are operating on it because of
<xsl:for-each select="msxsl:node-set($items)/item">, so you switch the
context to another "document", here the temporary tree.
Your second for-each works, because you don't switch the context to another
document.
> I thought that each time you execute a "select" that you're dealing with an
> RTF, regardless if the "select-or" is an xsl:for-each element or an
> xsl:variable element.
That's not correct, you always deal with a node-set, but not a RTF. The
msxml extension function node-set() converts the constructed RTF to a
node-set, because you can't operate with XPATH on a RTF. But this means too,
that switching the document has nothing to do with a RTF. For example
changing your first test with the variable to
<xsl:variable name="items" select="//item"/>
(which is much better than the RTF, because you don't need conversions and
processor dependend extension function),
you will have the same problem with the context.
Hope this makes some things clearer.
Joerg
Jeff Beadle wrote:
Hey Joerg,
Thanks for the quick response, and I'm very please it's the problem was just
in my lack of understanding RTFs.
However, why does the second for-each loop (the control loop in my
"experiment") work?
I guess what the second for-each is operating on (it's context) is not an
RTF? If it's not then what is it? What's its object structure?
I thought that each time you execute a "select" that you're dealing with an
RTF, regardless if the "select-or" is an xsl:for-each element or an
xsl:variable element.
Thanks again,
Jeff
-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@xxxxxx]
Sent: Tuesday, May 14, 2002 10:08 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Possible MSXML 3 / 4 bug: using a for-each on
xsl:variable / tre e-frag is misbehaving
Hello Jeff,
sorry, but it isn't a bug. You already said the solution: "given for-each's
context". You are switching the context to another XML tree (the RTF)
instead of the original document. What you can do is a second for-each
inside the first switching the context back to oringial document or simply
accessing the original document stored in a variable:
<xsl:variable name="orig" select="/"/>
> <xsl:template match="/">
> <output>
> <xsl:variable name="items" >
> <xsl:copy-of select="//item"/>
> </xsl:variable>
> <xsl:for-each select="msxsl:node-set($items)/item">
> <using_msxsl_node-set child-id="{@id}">
> <xsl:copy-of select="$orig/xml/an-element"/>
^^^^^
or
<xsl:for-each select="$orig">
<xsl:copy-of select="/xml/an-element"/>
</xsl:for-each>
> </using_msxsl_node-set>
> </xsl:for-each>
> <xsl:for-each select="//item">
> <NOT_using_msxsl_node-set child-id="{@id}">
> <xsl:copy-of select="/xml/an-element"/>
> </NOT_using_msxsl_node-set>
> </xsl:for-each>
> </output>
> </xsl:template>
> </xsl:stylesheet>
Regards,
Joerg
Jeff Beadle wrote:
Howdy all,
I looked through the archives and went to Microsoft's msxml site and
couldn't find any "PRB" or "BUG" reports regarding this "issue".
Here's what I'm seeing: Within an xsl:for-each element, where the select
is
made against an xsl:variable tree-frag, xpath statements are failing to
nodes outside of the given for-each's context.
Here's the xml:
<?xml version="1.0"?>
<xml>
<an-element>
<child id="child01"/>
<child id="child02"/>
</an-element>
<collection>
<item id="item01"/>
<item id="item02"/>
</collection>
</xml>
Here's the xslt:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<output>
<xsl:variable name="items" >
<xsl:copy-of select="//item"/>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($items)/item">
<using_msxsl_node-set child-id="{@id}">
<xsl:copy-of select="/xml/an-element"/>
</using_msxsl_node-set>
</xsl:for-each>
<xsl:for-each select="//item">
<NOT_using_msxsl_node-set child-id="{@id}">
<xsl:copy-of select="/xml/an-element"/>
</NOT_using_msxsl_node-set>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
Here's the output (I get):
<?xml version="1.0" encoding="utf-8" ?>
<output>
<using_msxsl_node-set child-id="item01" />
<using_msxsl_node-set child-id="item02" />
<NOT_using_msxsl_node-set child-id="item01">
<an-element>
<child id="child01" />
<child id="child02" />
</an-element>
</NOT_using_msxsl_node-set>
<NOT_using_msxsl_node-set child-id="item02">
<an-element>
<child id="child01" />
<child id="child02" />
</an-element>
</NOT_using_msxsl_node-set>
</output>
If this is not a user error/bug and truly is a bug within msxml, then this
one really [expletive deleted].
I can think of workarounds but they're a major pain in the you-know-what.
... oh, and for those will immediately ask: "Can you re-design the code
not
to use a variable?" Nope, I can't ... well, I'm pretty sure I can't.
Within the real code, I have to build and work with temporary
objects/results.
So, has anyone encountered this "issue"?
Thanks,
Jeff
--
System Development
VIRBUS AG
Fon +49(0)341-979-7419
Fax +49(0)341-979-7409
joerg.heinicke@xxxxxxxxx
www.virbus.de
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
| RSS 2.0 |
|
| Atom 0.3 |
|
|