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

RE: Why can't I use document() inside a template rule

Subject: RE: Why can't I use document() inside a template rule to match the template ?
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 17 Nov 2003 13:51:41 -0000
xsl template document
Since the two documents use different vocabularies, all your template
rules can match elements by name, and they don't need to specify which
document they expect to find those elements in.

If different documents contain overlapping vocabularies, then you can
use modes to distinguish which template rules are active for a given
call on xsl:apply-templates.

If you are really determined, you can write a template rule that only
applies to elements in a given document by writing:

<xsl:template match="e[generate-id(/) =
generate-id(document('a.xml'))]">

but it's probably grossly inefficient, and never necessary in practice.

Michael Kay



> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Narender S chauhan
> Sent: 17 November 2003 12:46
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Why can't I use document() inside a template 
> rule to match the template ?
> 
> 
> Hi,
>  I want to use document function in a template rule like 
> below in which primary XML and referenced XML through 
> document() function may be entirely
> different:
> 
> <xsl:template match="/">
> 	<xsl:apply-template select="document('Tes.xml')" /> 
> </xsl:template>
> 
> <xsl:template match="document(Tes.xml)">	// Browser 
> throws error at
> this point.
> 	<span>TEST</span>
> </xsl:template>
> 
> My question is, why can't I use document function in the 
> template rule or is there any alternative to such a problem. 
> A typical example would be as follows:
> --->doc1.xml
> <books>
> 	<book>
> 		<author>Graddy Booch</author>
> 		<title>UML User Guide</title>
> 	</book>
> 	<book>
> 		<author>Gamma</author>
> 		<title>Design Patterns</title>
> 	</book>
> </books>
> 
> ---> doc2.xml
> <readers>
> 	<reader>
> 		<name>naren</name>
> 		<occupation>Software Engineer</occupation>
> 	</reader>
> </readers>
> 
> ---->doc.xsl
> <?xml version='1.0' encoding="windows-1252"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="html" />
> 
> <xsl:template match="/">
> 	<html>
> 		<body>
> 			<span>
> 				<xsl:for-each 
> select="books/book/author">
> 					<xsl:value-of select="." />
> 					<br />
> 				</xsl:for-each>
> 				<xsl:apply-templates
> select="document('doc2.xml')" />
> 			</span>
> 		</body>
> 	</html>
> </xsl:template>
> <xsl:template match="document('doc2.xml')">	// Browser 
> gives an error to
> this
> 	<span>Test</span>
> </xsl:template>
> </xsl:stylesheet>
> 
> Any help would be great.
> ~Naren
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.