Subject: RE: [xsl] External XML Doc help From: David.Cantrell@xxxxxxxxxxxxx Date: Mon, 17 Mar 2003 15:59:57 -0600 |
> <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] External XML Doc help, Passin, Tom | Thread | [xsl] xalan-java DTM ID error, Greg Martel |
RE: [xsl] External XML Doc help, Passin, Tom | Date | Re: [xsl] External XML Doc help, Karl Stubsjoen |
Month |