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

How to use document() of doc() function with copy idio

Subject: How to use document() of doc() function with copy idiom, or how to access nodes of doc() tree
From: Abel Braaksma Online <abel.online@xxxxxxxxx>
Date: Tue, 25 Jul 2006 16:02:45 +0200
xml.doc function in xslt
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

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.