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

Re: Resetting context to main document with "document(

Subject: Re: Resetting context to main document with "document()"?
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Sat, 9 Mar 2002 00:08:49 +0100
Re:  Resetting context to main document with "document(
That's really a big stylesheet with many document()'s. Can't you remove one
or another template to see where the 'trash' comes from?

Here an example:

file1.xml

<xml>
    <node name="a">123</node>
    <node name="b">456</node>
    <node name="c">789</node>
</xml>

file2.xml

<xml>
    <nodes>
        <c/>
        <a/>
    </nodes>
</xml>

XSL

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
    <xsl:variable name="file1" select="/"/>
    <xsl:variable name="file2" select="document('file2.xml')"/>

    <xsl:template match="/">
        <xsl:for-each select="$file2/xml/nodes/*">
            <xsl:variable name="name" select="name()"/>
            <xsl:for-each select="$file1/xml">
                <xsl:value-of select="node[@name=$name]"/>
                <xsl:text>,</xsl:text>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Output:

789,123,

No trash, only the expected output. Maybe this helps a bit.

Joerg


> Hi Joerg,
> here is the stylesheet - in order to properly test it I would need to send
> you also the xml files etc. If necessary, I can send the whole set.
> The problem is that when I set the variable to "/", it outputs as an error
> message words from the "templates" file (what I interpreted as trash...),
> complaining "is not a valid URL".
> Now I fixed it passing the same pathname twice to the xsl processor, once
> as the name of the parsed file and once as a simple parameter. Not
elegant,
> isn't it?
> Thank you very much,
> Costantino


> <xsl:variable name="doc" select="/"/> is THE one and in any case best
> solution to handle this problem. That MSXML outputs trash is not standard,
> it must come from your stylesheet. You can post your complete stylesheet
> here and we will have a look at it.
>
> Regards,
>
> Joerg


 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.