sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
usenetjs@hotmail.com's Avatar

Need help in XMLT


Question posted by: usenetjs@hotmail.com (Guest) on July 18th, 2006 02:25 PM
Hello,

I am very new to xsl. So, If anyone can help eme out, it would be
great. I have the following problem.

I have 2 xml documents.

Document 1: A collection of items

<items>
<item>
<id>...</id>
<location>...</location>
...
</item>
<item>
...

</item>
<items>


Document 2: A collection of ids (which is a subset of ids from
document 1)
<ids>
<id... </id>
<id... </id>
<ids>

Needed output in xml: Filtered document 1 consisting only of items with
the ids from document 2.

-js

1 Answer Posted
George Bina's Avatar
Guest - n/a Posts
#2: Re: Need help in XMLT

Hi,

You can start with a recursive copy template and add a rule to check if
the item shold be copied or not. Assuming the document 2 is named
ids.xml then you need a stylesheet like below

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

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="item">
<xsl:if test="id=document('ids.xml')/ids/id">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Join Bytes! wrote:
Quote:
Originally Posted by
Hello,
>
I am very new to xsl. So, If anyone can help eme out, it would be
great. I have the following problem.
>
I have 2 xml documents.
>
Document 1: A collection of items
>
<items>
<item>
<id>...</id>
<location>...</location>
...
</item>
<item>
...
>
</item>
<items>
>
>
Document 2: A collection of ids (which is a subset of ids from
document 1)
<ids>
<id... </id>
<id... </id>
<ids>
>
Needed output in xml: Filtered document 1 consisting only of items with
the ids from document 2.
>
-js


 
Not the answer you were looking for? Post your question . . .
197,043 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,043 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors