RE: [xsl] Data-Dtriven node selection

Subject: RE: [xsl] Data-Dtriven node selection
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Sun, 13 Mar 2005 18:25:19 +0000
David, it seemed from a subsequent post that you could achieve what you want via a standard XSL transform. Still, you may want to look at this thread



What I want to do is this: use a xml file to specify
which nodes from another xml file to select using a
data-driven xslt template.

For example:

1) My base xml file (LR.xml) , from which I want to
select nodes in a data-drivem manner

	<Name>David Laub</Name>
	<Addr>4645 W. Jerome</Addr>
	<Telephone>847-674 2266</Telephone>

2) My data-driven "selector" file (LRLookup1.xml) -
the intent being for this specific example to select
only the name & city nodes - I also want to rename the

	<Element from="LR/Name" to="Name"/>
	<Element from="LR/City" to="HomeTown"/>

3) Finally my stylesheet (GenericLRFiler.xsl) - which
doesn't quite work - I associate it with LRLookup1.xml
and the stylesheet then explicitly also reads the
LR.xml file

The key line is:

<xsl:value-of select="$LossReport/./@from"/>

That's the line that fails: I want to append in a
data-driven manner the specific nodes to the existing
node-tree in the variable $LossReport.  The XPath
isn't smart enough to know I want to evaluate ./@from
(which holds LR/Name & LR/City from the data-driven
selector file) I guess it just thinks I'm appending
the string ./@from as part of the XPath, which returns

I can succesfully hard code a specific node

<xsl:value-of select="$LossReport/LR/City"/>

but that defeats teh whole purpose of the whole

Here's the full stylesheet

<xsl:stylesheet version="1.0"
	<xsl:output method="xml" indent="yes"/>
	<xsl:variable name="LossReport"
	<xsl:template match="*">
		<xsl:element name="LRFilteredData">
	<xsl:template match="/LRLookUp1/Element">
		<xsl:element name="{./@to}">
			<xsl:value-of select="$LossReport/./@from"/>

This is actual output:


what I want for output is:

	<Name>David Laub</Name>

So is this magic do-able?

Thanks in advance

David Laub

Express yourself instantly with MSN Messenger! Download today - it's FREE!

Current Thread