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

RE: How to use document() of doc() function with copy

Subject: RE: How to use document() of doc() function with copy idiom, or how to access nodes of doc() tree
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 25 Jul 2006 15:32:20 +0100
xsl copy function
Your problem seems to be very simple:

<xsl:value-of select="document($input-file)" />

The xsl:value-of instruction writes a text node whose value is the
string-value of the input. The string value of a document node is the
concatenation of all its text, with no hierarchic structure. You probably
want xsl:copy-of or xsl:sequence.

Note also: XSLT 2.0 does allow you to run a stylesheet with no principal
input document. Just specify a named template as the entry point. If using
the Saxon command line you do this with the "it" option, e.g. "-it main".

Michael Kay

> -----Original Message-----
> From: Abel Braaksma Online [mailto:abel.online@xxxxxxxxx] 
> Sent: 25 July 2006 15:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  How to use document() of doc() function with 
> copy idiom, or how to access nodes of doc() tree
> Dear list,
> I have been trying some variants, but I think I've been stuck 
> in the namespaces and context location labyrinth. What I want 
> seems easy: I have a set of documents, all valid XML and want 
> to output the contents of these documents, either as one big 
> XML document, or as a set of documents.
> In essence: using the copy idiom on each document and, 
> optionally, doing something with the tree that is input from 
> the document() function.
> Problem: all my nodes are gone and the external documents are 
> output as one big piece of text (except for the tags "doc" 
> and "input-file") and I don't seem to be able to find 
> specific values, like the "tableData" tag below. I know this 
> is usually a namespace problem, but I don't know how to solve 
> it. Because it does not even work for one input file, I 
> provide a stripped down version of my XSLT below, that parses 
> one external xml document.
> Namespace of input xml document: this is equal to the current 
> xslt document (just because saxon needs an input document. I 
> don't actually use it) Namespace of document() xml doc: 
> "http://www.nuntia.com/tablewiz1.0"
> Namespace of output document: "http://www.nuntia.com/tablewiz1.0"
> XSLT file:
> <xsl:stylesheet version="2.0" 
>     xmlns = "http://www.nuntia.com/tablewiz1.0"
>     exclude-result-prefixes = "nuntia xsl xs fn xdt"
>     xpath-default-namespace = "http://www.nuntia.com/tablewiz1.0">
>     <xsl:output indent="yes" />
>     <!-- name of the input file or files -->
>     <xsl:param name="input-file" select="'test.xml'" />
>     <!-- load the documents -->
>     <xsl:variable name="documents">
>             <doc>
>                 <input-filename><xsl:value-of select="." 
> /></input-filename>
>                 <xsl:value-of select="document($input-file)" />
>             </doc>
>     </xsl:variable>
>     <xsl:template match="/">
>         <output>
>             <xsl:for-each select="$documents/doc">
>                 <xsl:apply-templates select="." mode="copy" />
>             </xsl:for-each>
>         </output>
>     </xsl:template>
>     <xsl:template match="node() | @*" mode="copy">
>         <xsl:copy>
>             <xsl:apply-templates select="@* | node()" mode="copy"/>
>         </xsl:copy>
>     </xsl:template>
> </xsl:stylesheet>
> XML file that is input using document() function, namely test.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <tableData name="bla">
>    <description>Table description</description>
>    <rows total="3">
>        <row id="35" row-index="not-applicable">
>            <cell>Row1Cell1</cell>
>            <cell>Row1Cell2</cell>
>        </row>
>    </rows>
> </tableData>

Current Thread


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.
First Name
Last Name
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.