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

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
sara agai
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

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.