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

RE: External XML Doc help

Subject: RE: External XML Doc help
From: David.Cantrell@xxxxxxxxxxxxx
Date: Mon, 17 Mar 2003 15:59:57 -0600
external xml html
> <xsl:for-each select="document('myxmldoc.xml')//testing/test">
> 	<xsl:value-of select="."/>  
> 	<!-- '.' is the current node reference, i.e. whatever 
> 'test' node you are on in the loop --> </xsl:for-each>

OK, when I first looked at the question I thought a template match was
requested, but it wasn't so I came up with the for-each above. But it made
me wonder, can you match based on external documents? So I whipped up the
following:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:output method="html"/>
	
	<xsl:variable name="xmldoc" select="document('default.xml')"/>
	
	<xsl:template match="/">
		<html>
			<body>
				<xsl:apply-templates
select="$xmldoc/testing/test"/>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="testing/test">
		<xsl:value-of select="."/><br/>
	</xsl:template>

</xsl:stylesheet>

Contents of default.xml:

<testing>
    <test>1234</test>
    <test>1234</test>
    <test>1234</test>
    <test>1234</test>
</testing>

Now, this works great, I just viewed it in IE since it points to itself just
for quick testing. But my template originally used the same pattern as the
apply-templates element, i.e. "$xmldoc/testing/test", however IE reported
that I could not use $xmldoc ("variables") in a match pattern. I can't embed
the document() call in it's place either, i.e.
"document('default.xml')/testing/test".

Why is that?

It looks like I can write a template for a general element set in the
stylesheet, and the documents called in are somehow merged with the main
document transformed. I'm not grokking exactly how they are merged, and to
confess I never really needed to before. Like I said, this was simply to
satisfy my curiosity, but while answering one question it naturally prompted
two more...

Thanks!
-dave

 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.