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 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Doo KimSubject: How do you select a particular node based on an element value?
Author: Doo Kim
Date: 29 Mar 2005 12:47 PM
Hi,

I'm new to XSLT and I was hoping someone can help me with the following query:

I have a source XML message like the one below.


<?xml version="1.0"?>
<ns:Messages xmlns:ns="http://help.com">
<ns:Message1>
<ns0:help xmlns:ns0="HTTP:help">
<Detail>
<ID>123</ID>
</Detail>
<Detail>
<ID>444</ID>
</Detail>
</ns0:help>
</ns:Message1>
<ns:Message2>
<ns0:help2 xmlns:ns0="HTTP:help">
<row>
<ID>123</ID>
<Name>Bob</Name>
</row>
<row>
<ID>555</ID>
<Name>John</Name>
</row>
<row>
<ID>444</ID>
<Name>Mary</Name>
</row>
</ns0:help2>
</ns:Message2>
</ns:Messages>


Would I would like to do is map the values of Message2 where the ID exists in Message 1 to the target structure as such:


<ns:Messages xmlns:ns="http://help.com">
<ns:Message1>
<ns1:help3 xmlns:ns1="HTTP:help">
<row>
<ID>123</ID>
<Name>Bob</Name>
</row>
<row>
<ID>444</ID>
<Name>Mary</Name>
</row>
</ns1:help3>
</ns:Message1>
</ns:Messages>


Any help would be greatly appreciated.
Thank you.
Best Regards,
Doo

Postnext
(Deleted User) Subject: How do you select a particular node based on an element value?
Author: (Deleted User)
Date: 29 Mar 2005 01:36 PM
to do it in mapper, you need to do following steps. becase it involves structure change and
conditional transformation, you would need 'if block' to help you.

1.choose source and target schema by your xml example.
2.right click on the middle pane and choose 'xsl instructions/for-each'
3.link the 'row' node in message2 from source tree to the left port of for-each block
4.right click on the middle pane and choose 'xsl instructions/if' and link from for-each
outport(at right) to 'if' block inport(at top).
5.link 'if block' outport(at right) to target tree ns1:help3 node
6.link ID in message2 from source tree to ID in target tree
7.link Name in message2 from source tree to Name in target tree

you are almost there except for you need to specify you condition in 'if block'. you can double click
on the 'if block' left port to type the following
/ns:Messages/ns:Message1//ID[.=current()/ID]


after these steps you should see following code, it will do the job for your transformaiton.

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="HTTP:help" xmlns:ns="http://help.com">
<xsl:template match="/">
<ns:Messages>
<ns:Message1>
<xsl:for-each select="ns:Messages/ns:Message2/ns0:help2/row">

<xsl:if test="/ns:Messages/ns:Message1//ID[.=current()/ID]">
<ns1:help3>
<row>
<ID>
<xsl:value-of select="ID"/>
</ID>
<Name>
<xsl:value-of select="Name"/>
</Name>
</row>
</ns1:help3>
</xsl:if>
</xsl:for-each>
</ns:Message1>
</ns:Messages>
</xsl:template>
</xsl:stylesheet>

Let us know if you need further assistance.

Posttop
Doo KimSubject: How do you select a particular node based on an element value?
Author: Doo Kim
Date: 29 Mar 2005 04:26 PM
It works perfectly! Thank you so much for your help Song.

Best Regards,
Doo

 
Topic Page 1 2 3 4 5 6 7 8 9 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.