Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2005, 05:57 PM
Registered User
 
Join Date: Apr 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default using 2 sets of xml data from 1 xslt

greetings,

I have an xslt page that will incorporate data from 2 separate xml files. I have references to these xml files set up as variables, $data1 and $data2. I can easily access data from either file by using:

Code:
<xsl:value-of select="$data1/node1/node2" />
or
Code:
<xsl:value-of select="$data2/node1/node2" />
my problem comes in when I try to use a template to match to either of these.

I'm trying to do:
Code:
<xsl:template name="header_baseinfo" match="$data1/node1/node2[@name='header']">
    <p>Computer Name: <xsl:value-of select="computername" /></p>
    <p>Report Name: <xsl:value-of select="reportname" /></p>
</xsl:template>
and then call this template (by name) inside the master page template. When I do this, I get an error telling me that I cannot use a variable name in the "match" attribute.

I know I could just as easily do:
Code:
<xsl:template name="header_baseinfo" >
    <p>Computer Name: <xsl:value-of select="$data1/node1/node2[@name='header']/computername" /></p>
    <p>Report Name: <xsl:value-of select="$data1/node1/node2[@name='header']reportname" /></p>
</xsl:template>
but this seems terribly inefficient. There's got to be a better way.

Any ideas?

 
Old April 1st, 2005, 06:06 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Template rules aren't specific to a particular document, they match a pattern whatever document it appears in. You can control which documents are processed based on the nodes you select for processing in apply-templates. If you need different template rules that match the same pattern occurring in different documents, use modes.

But if you're calling a template by name, then the match pattern is completely ignored, so why specify it?

If you're worried about computing $data1/node1/node2[@name='header'] twice, then put the result in a variable.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 1st, 2005, 06:31 PM
Registered User
 
Join Date: Apr 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, so I did:

Code:
<xsl:template name="header_baseinfo">
    <xsl:variable name="base" select="$data1/node1/node2[@name='header']" />
    <p>Computer Name: <xsl:value-of select="$base/computername" /></p>
    <p>Report Name: <xsl:value-of select="$base/reportname" /></p>
</xsl:template>
and it seems to work fine. But this scenario seems to be closer to what I'm looking for:
 
Quote:
quote:If you need different template rules that match the same pattern occurring in different documents, use modes.


I have not been able to figure out how this attribute works (at least not for what I'm trying to do). Might you have an example you could point me to?






Similar Threads
Thread Thread Starter Forum Replies Last Post
issue with data sets kaliaparijat ASP.NET 2.0 Professional 1 June 22nd, 2008 11:14 AM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
How to Query XML Data from XSLT Form kwilliams XSLT 1 December 3rd, 2005 06:14 AM
How to calculate the number of XML data sets? zhao790 XML 4 October 29th, 2003 12:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.