[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Output common IDs
Subject: Re: Output common IDs
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jan 2011 09:29:05 +0000
|
I think (perhaps) you've made the common mistake of imagining that
contains() tests whether a particular sequence contains a particular
value. In fact, contains() does something quite different - it tests
whether a string contains a substring.
To test whether a sequence $S contains the value $V, just use the "="
operator - ($S = $V).
In fact this problem seems to be much simpler than you are making it: I
think it's just
<xsl:template match="/AllIds">
<xsl:value-of select="tokenize(., '\s+')[. = tokenize(doc('PageIDs.xml')/id, '\s+')]"/>
</xsl:template>
Michael Kay
Saxonica
On 26/01/2011 06:11, Suresh wrote:
Hi,
I have a xml file (PageIDs.xml) which contains several IDs. I have
another file which contains ID and URI separated by a tab(AllIDs.xml)
The question is, For each tokenized ID contained in PageIDs.xml file I
want to test all IDs in AllIDs.xml and if ID test matches output
matching line as text. This is simple for members in the list, I tried
but I could not solve this using XSLT 2.0
PageIDs.xml
-------------------
<id>
BD6131A5-527C-11DF-A29F-00144F3EA4A4
DCA7D4CA-312D-11DF-A385-00144F3EA4A4
DD762167-312D-11DF-A385-00144F3EA4A4
DDB79742-312D-11DF-A385-00144F3EA4A4
3D74A11A-839A-11DF-82F6-00144F3EA4A4
...
</id>
AllIDs.xml
---------------
<AllIds>
DCA7D4CA-312D-11DF-A385-00144F3EA4A4 /accounts-overview/dkadoemfew
8ED29EEA-6460-11DF-8508-00144F3EA4A4 redirect.go?target=payxsxs
EC2152EB-4593-11DF-BCB6-00144F3EA4A4 /accounts-overview/redirect.go?target=feljfweij
997A1170-474A-11DF-BCB6-00144F3EA4A4 redirect.go?target=woqiepoqie
DD4AF2B0-312D-11DF-A385-00144F3EA4A4 /accounts-overview/e32i2je2
BD6131A5-527C-11DF-A29F-00144F3EA4A4 /contactus/about-contact
...
</AllIds>
This is the XSLT I've written...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs" version="2.0">
<xsl:output method="text"/>
<xsl:variable name="FilteredPageIds" select="doc('pageIDs.xml')/id"/>
<xsl:template match="/AllIds">
<xsl:variable name="AllListedIds" select="tokenize(text(),'\t+')"/>
<xsl:for-each select="$AllListedIds">
<xsl:for-each select="tokenize($FilteredPageIds,'\n')">
<xsl:variable name="CurrentPageId"
select="normalize-space(current())"/>
<xsl:if test="contains($CurrentPageId, $AllListedIds)">
<xsl:value-of select="$AllListedIds"/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This fails at contains because the item is a collection and I am not
sure how to handle them.
Expected output for IDs matching in PageIDs.xml,
BD6131A5-527C-11DF-A29F-00144F3EA4A4 /contactus/about-contact
Thanks.
--
Suresh
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|