RE: [xslt] how to access default xml



you want to put the original XML tree into a global variable so you can
access it whenever you need. At the top level of the XSL, put:

<xsl:variable name="default-xmlfile" select="/"/>

Also, when you make repeated document function calls to the same document,
why not put the result in a variable once and then reuse it.

<xsl:variable name="test-xmlfile" select="document('test.xml')/rootnode"/>

<xsl:apply-templates select="$test-xmlfile"/>

One more thing you might want to do is set the xsl:output to text.


> -----Original Message-----
> From: xslt-admin@gnome.org [mailto:xslt-admin@gnome.org]On Behalf Of
> Bernhard Zwischenbrugger
> Sent: Wednesday, September 26, 2001 2:32 AM
> To: xslt@gnome.org
> Subject: [xslt] how to access default xml
>
>
> this is not a bugreport
>
> I have a Problem to access the default-xmlfile after
> doing
> <xsl:apply-templates select="document('test.xml')">
>
> After this command I can access the nodes of test.xml
> but can't access the nodes of the default xml.
>
> The only possibility I found is to open the default
> document again with the document function.
>
> Is there an easier way to do that?
>
> AN EXAMPLE:
> ============
>
> default.xml
> ========
> <?xml version="1.0"?>
> <test>This is the default document</test>
>
> test.xml
> ======
> <?xml version="1.0"?>
> <nodes>
> <node>one</node>
> <node>two</node>
> </nodes>
>
> test.xslt
> ======
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
> xmlns:libxslt="http://xmlsoft.org/XSLT/namespace">
>
> <xsl:template match="/">
>         <xsl:apply-templates select="document('test.xml')" mode="test"/>
> </xsl:template>
>
> <xsl:template match="*" mode="test">
> <xsl:for-each select="/nodes/*">
> <xsl:value-of select="."/>
> --------------------------
> <!--   T H  E    P R O B L E M -->
> <!-- switch back to default xml-document -->
>         <xsl:apply-templates select="document('default.xml')"
> mode="defaultxml"/>
> </xsl:for-each>
>
> </xsl:template>
>
> <xsl:template match="*" mode="defaultxml">
> <xsl:value-of select="."/>
> **********************
> </xsl:template>
>
> </xsl:stylesheet>
>
> command
> ========
> xsltproc test.xslt default.xml
>
> result
> ====
> <?xml version="1.0"?>
> one
> --------------------------
> This is the default document
> **********************
> two
> --------------------------
> This is the default document
> **********************
>
>
> _______________________________________________
> xslt mailing list
> xslt@gnome.org
> http://mail.gnome.org/mailman/listinfo/xslt
>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]