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
http://www.saxonica.com/
-----Original Message-----
From: Abel Braaksma Online [mailto:abel(_dot_)online(_at_)xs4all(_dot_)nl]
Sent: 25 July 2006 15:03
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--