XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
John HigginsSubject: Using variables in a select attribute
Author: John Higgins
Date: 30 Nov 2005 08:11 AM
I am attempting to convert 2 XML files into one and would like to use an attribute values to open the second file and assign the node path. I have successfully opened the second file and accessed the desired data using the statement below (I plagerized this from XSLT mapper):

<xsl:copy-of select="document($filename)/boiler_plate/branch_name"/>

I would like to replace "/boiler_plate/branch_name" with:

<xsl:copy-of select="document($filename)$nodename"/> (or correct syntax)

but get the error message "Unexpected token in xsl:copy-of".

I have attached snippets of the primary XML and transform stylesheet for specific information.


DocumentXML_Question1.TXT
Text

Postnext
Tony LavinioSubject: Using variables in a select attribute
Author: Tony Lavinio
Date: 30 Nov 2005 09:28 AM
You must supply the pathname so that it can be resolved at compile-time,
not at run-time, so variable substitution in the path won't work.

What you can do is something like this:
<xsl:copy-of select="document($filename)/node()[local-name(.) = $nodename]"/>

Postnext
John HigginsSubject: Using variables in a select attribute
Author: John Higgins
Date: 30 Nov 2005 11:13 AM
Originally Posted: 30 Nov 2005 10:58 AM
Tony, thanks for the quick turn around. I have tried your suggestion, but cannot get it to work (it compiles, but does not make a copy-of the text). As a novice, I am obviously missing something. Am I supposed to substitute "local-name" with something (none of the books I have reference such an XPath function)? Should the nodename be "/boiler_plate/branch_name" (boiler_plate being the root element of boiler_plate.xml and branch_name the child node I wish to copy)?

Postnext
(Deleted User) Subject: Using variables in a select attribute
Author: (Deleted User)
Date: 30 Nov 2005 11:42 AM
John,

Can you attach the .xml data and the .xsl file so we can take a look?

Thanks
Clyde

Postnext
John HigginsSubject: Using variables in a select attribute
Author: John Higgins
Date: 30 Nov 2005 12:01 PM
Clyde, I will need some time to sanitize the files for transmittal (an hour or so), but, yes I can.

Postnext
John HigginsSubject: Using variables in a select attribute
Author: John Higgins
Date: 30 Nov 2005 12:41 PM
Clyde,
Attached are the primary XML (item_spec.xml) the secondary (bp_file.xml) and the stylesheet (item_tran_1.xsl). If you substitute "/boiler_plate/branch_name" for "/node()..." in the copy-of, you can see the output I expect.


Documentitem_spec.xml
Text

Documentbp_file.xml
Text

Documentitem_trans_1.xsl
Text

Postnext
(Deleted User) Subject: Using variables in a select attribute
Author: (Deleted User)
Date: 30 Nov 2005 01:22 PM
John,

The local-name(.)=$nodename idea didn't work because $nodename does not contain a node name, it contains an entire xpath expression, in this case /boiler_plate/branch_name.

So, what you need is something which will dynamically compile and evaluate that xpath expression. Lucky for you, the Saxon processor has that. It you are willing and able to use Saxon (select the saxon processor in the scenario processor tab), then the attached fragment does what you need. I tried this and it worked in saxon 8.6.1. If you use saxon 6, you should change the xmlns:saxon= to "http://icl.com/saxon". Remove the <var>....</var> when you are happy that it works ok.


<xsl:template match="tp_header">
<xsl:variable name="filename" select="@file_id"/>
<xsl:variable name="nodename" select="@element"/>
<xsl:variable name="xpathexpr" select="concat('document(&quot;', $filename, '&quot;)', $nodename)"/>
<var><xsl:value-of select="$xpathexpr"/></var>
<xsl:copy-of select="saxon:evaluate($xpathexpr)" xmlns:saxon="http://saxon.sf.net/"/>
</xsl:template>

If you can't use saxon, then I would suggest you write a java extension which does the same thing as saxon:evaluate. This is not as hard as it seems, just invoke an xslt processor.

Good luck,
Clyde

Posttop
John HigginsSubject: Using variables in a select attribute
Author: John Higgins
Date: 30 Nov 2005 02:53 PM
Worked like a charm. Many Thanks.

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.