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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Scott RennerSubject: selecting nodes in another XML document
Author: Scott Renner
Date: 05 Aug 2005 12:39 PM
I'm trying to select an element and its children from another document, based upon the value of an element in my first document. I know I don't have the correct syntax to select the correct items.

Here is a example.

First document
...
<doc>
<device>
<model>1234AB></model>
</device>
</doc>

Second document

<devices>
<model id="1234AB">
<feature>1234</feature>
<color>Red</color>
</model>
</devices>

Output should be:
<doc>
<device>
<model>1234AB></model>
<feature>1234</feature>
<color>Red</color>
</device>
</doc>

Here is what I have come up with:
<xsl:template match="/doc/device">
<xsl:copy-of select="document('ConfigBase.xml',/devices/model[@id='model'])"/>
</xsl:template>
This doesn't work because @id='model' is looking for the literal "model" as the id. How do I reference the current value of "model" in the @id statement?

Thanks!

Scott

Postnext
Ivan PedruzziSubject: selecting nodes in another XML document
Author: Ivan Pedruzzi
Date: 05 Aug 2005 01:51 PM
Scott,

You have to use a variable like in the following code

<xsl:template match="/doc/device">
<xsl:variable name="model" select="model"/>
<xsl:copy-of select="document('ConfigBase.xml',/devices/model[@id=$model])"/>
</xsl:template>

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Scott RennerSubject: selecting nodes in another XML document
Author: Scott Renner
Date: 05 Aug 2005 03:01 PM
That did the trick!

Thanks

Postnext
Scott RennerSubject: selecting nodes in another XML document
Author: Scott Renner
Date: 05 Aug 2005 04:18 PM
Well, I think I'm almost there, but I still have a problem.

If the first file is:
<doc>
<version>1.0</version>
<date>12/12/04</date>
<model>1234AB</model>
</doc>

and the second file is
<devices>
<model id="1234AB>
<feature>1234</feature>
<color>Red</color>
</model>
</devices>

the xsl file is:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"/>
<xsl:template match="/config/device">
<xsl:variable name="model" select="model"/>
<xsl:copy-of select="document('ConfigBase.xml')/config/device/model[@id=$model]/*"/>
</xsl:template>
</xsl:stylesheet>

The output is now
<?xml version="1.0" encoding="UTF-16"?>
1.012/12/04
<feature>1234</feature>
<color>Red</color>

The lines that do not match the template, the values are just being output. How do I get the stylesheet to output the original XML line with the element tags still in place?

Scott

Posttop
Ivan PedruzziSubject: selecting nodes in another XML document
Author: Ivan Pedruzzi
Date: 05 Aug 2005 04:48 PM
Assuming that the main input is main.xml
<doc>
<version>1.0</version>
<date>12/12/04</date>
<model>1234AB</model>
</doc>

and the second document is ConfigBase.xml
<config>
<device>
<model id="1234AB>
<feature>1234</feature>
<color>Red</color>
</model>
</device>
</config>

you should be able to do the following

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"/>

<xsl:template match="/">
<root>
<!-- use for-each in case your main.xml contains more then one model -->
<xsl:for-each select="/doc/model">
<xsl:variable name="model" select="."/>
<xsl:copy-of select="document('ConfigBase.xml')/config/device/model[@id=$model]/*"/>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>

Hoep this helps
Ivan Pedruzzi
Stylus Studio Team

   
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.