[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: The document() function....again !!


Subject: RE: The document() function....again !!
From: Ed Blachman <EdB@xxxxxxxxxxx>
Date: Fri, 13 Oct 2000 18:04:33 -0400

Melvin --

> First let me say ALL files are in in the exact same directory....
> 
> I am using a string literal as my  URI parameter
>              <xsl:apply-templates
> select="document(somefile.xml)/some_element[@aval='true']"
> " Open the somefile.xml file and return the <some_elemement> 
> node collection
> whose aval attribute is true. "

Seems like you'd want instead

<xsl:apply-templates
select="document('somefile.xml')//some_element[@aval='true']"/>

-- // rather than / as otherwise you'd match either exactly one node (if
some_element were the top-level element in somefile.xml and if its aval
attribute's value were 'true') or nothing
-- and you have to quote the URI of your file (here somefile.xml) so that it
will treated as a string rather than (here) the name of some element whose
content is to be converted to a string (which would almost certainly make it
the null string in your case)
 
> followed by..
> 
> <xsl:template match=some_element />
>        <H1> FOUND IT </H1>

Here you almost certainly want

<xsl:template match="some_element">
   <H1> FOUND IT </H1>
</xsl:template>

-- because as written, the H1 element you give is *not* part of your
template.

The following sample was tested and works with Instant Saxon.

dummy.xml:
---
<?xml version="1.0"?>
<dummy/>

test.xml
---
<?xml version="1.0"?>
<dummy>
	<some_element aval="false"></some_element>
	<some_element aval="true"></some_element>
	<some_element></some_element>
	<some_other_element>
		<some_element aval="true"></some_element>
	</some_other_element>
</dummy>
---

test.xsl:
---
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" version="1.0" encoding="UTF-8"
indent="yes"/>
	<xsl:template match="/">
		<html>
			<body>
			<p>Did we find it?</p>
			<xsl:apply-templates
select="document('test.xml')//some_element[@aval='true']"/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="some_element">
		<h1> FOUND IT! </h1>
	</xsl:template>
</xsl:stylesheet>
---

command line:
---
prompt> "d:\Program Files\Instant Saxon\saxon.exe" dummy.xml test.xsl >
test.htm
---

result (test.htm):
---

<html>
   <body>
      <p>Did we find it?</p>
      <h1> FOUND IT! </h1>
      <h1> FOUND IT! </h1>
   </body>
</html>
---

HTH, ed


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



Current Thread