Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - Need help in XMLT

 
Thread Tools Search this Thread
Old 07-18-2006, 02:32 PM   #1
Default Need help in XMLT


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



usenetjs@hotmail.com
  Reply With Quote
Old 07-18-2006, 10:32 PM   #2
George Bina
 
Posts: n/a
Default 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"
xmlnssl="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

wrote:
> 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


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump