This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to use saxon:node-set(document($f)) ?


Kay Michael wrote:
> 
> I don't think there are any circumstances in which saxon:node-set() should
> produce an empty node-set, so I'd be grateful if you could supply a complete
> stylesheet that demonstrates the problem.

OK - here's a simple demo.

--- nodetest.xsl ---
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:saxon="http://icl.com/saxon"
                xmlns:file="java.io.File"
                extension-element-prefixes="saxon"
                exclude-result-prefixes="saxon">

<xsl:output method="xml" />

<xsl:param name="CONFIG_FILE" select="'???'" />

<xsl:variable name="config_doc" select="document($CONFIG_FILE)" />

<xsl:variable name="config_ns">
  <xsl:if test="$CONFIG_FILE != '???' and
      file:exists(file:new($CONFIG_FILE))">
    <xsl:value-of select="saxon:node-set(document($CONFIG_FILE))" />
  </xsl:if>
</xsl:variable>

<xsl:template match="/">
  --- start $config_doc ---
<xsl:copy-of select="$config_doc" />
  --- end $config_doc ---

  --- start $config_ns ---
<xsl:copy-of select="$config_ns" />
  --- end $config_ns ---
</xsl:template>

</xsl:stylesheet>
--- nodetest.xsl ---

--- input_document.xml ---
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE input_document>

<source_document />
--- input_document.xml ---

--- configuration.xml ---
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE configuration>

<configuration>
  <directory_alias alias="HOME" directory="/home/hedley" />
</configuration>
--- configuration.xml ---

Using Saxon 5.3 :

java com.icl.saxon.StyleSheet input_document.xml \
    nodetest.xsl CONFIG_FILE=configuration.xml

produces

<?xml version="1.0" encoding="utf-8" ?>
  --- start $config_doc ---
<configuration>
  <directory_alias alias="HOME" directory="/home/hedley"/>
</configuration>
  --- end $config_doc ---

  --- start $config_ns ---

  --- end $config_ns ---

Incidentally, I originally had the output for each variable inside
a <xsl:message> element and was getting some unusual results :

<xsl:message>
  <xsl:text>$config_doc = `</xsl:text>
  <xsl:copy-of select="$config_doc" />
  <xsl:text>'</xsl:text>
</xsl:message>

gives

$config_doc = `<configuration
  ><directory_alias alias="HOME" directory="/home/hedley"
'

which isn't well-formed. Section 13 says something about
"instantiating the content to create an XML fragment" -I'm
not sure exactly what this means, but I wouldn't have
expected the behaviour above.

Any help much appreciated.

-- 
Warren Hedley
Department of Engineering Science
Auckland University
New Zealand


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]