Need help in XMLT

U

usenetjs

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
 
G

George Bina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top