Subject: Re: [xsl] Output common IDs From: Michael Kay <mike@xxxxxxxxxxxx> Date: Wed, 26 Jan 2011 09:29:05 +0000 |
<xsl:template match="/AllIds"> <xsl:value-of select="tokenize(., '\s+')[. = tokenize(doc('PageIDs.xml')/id, '\s+')]"/> </xsl:template>
Michael Kay Saxonica
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Output common IDs, David Carlisle | Thread | Re: [xsl] Output common IDs, Brandon Ibach |
Re: [xsl] Output common IDs, David Carlisle | Date | Re: [xsl] Output common IDs, Brandon Ibach |
Month |