Hi Jeff,
Here's one way to do it, but without keys. Though it might be that the
lookup loop is optimized by the processor, at least it will be faster
than your //text(). Either $source, $lookup or both will be your
external documents for source and lookup table. As long as they remain
global variables or parameters, you can use them in the match-clause of
the xsl:template, giving the processor all opportunity to use the pull
model (or was it push model? I keep mixing them up... see thread "is
XSLT dead").
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes" />
<xsl:variable name="lookup">
<entry>text 1</entry>
<entry>text 2</entry>
</xsl:variable>
<xsl:variable name="source">
<head>some text 1 some text some text some text</head>
<head>nothing here some text some text some text</head>
<head>some text 2 some text some text some text</head>
</xsl:variable>
<xsl:template match="/" name="main">
<xsl:apply-templates select="$source/head" />
</xsl:template>
<xsl:template match="head[not((for $i in $lookup/entry return
matches(., $i))[.])]">
<found this="{.}" />
</xsl:template>
<xsl:template match="*" />
</xsl:stylesheet>
Jeff Sese wrote:
Hi,
I have a reference file like this:
<root>
<entry>text 1</entry>
<entry>text 2</entry>
</root>
the entry elements may reach up to more than a thousand. I need to
generate a list of entry elements that does not have a match in my
source xml.
my source xml looks like:
<source>
<head>some text 1 some text some text some text</head>
</source>
what i do in my xslt is to iterate each of the entry elements and try
to look for a match if there is none then i report it.
<xsl:template match="/">
<xsl:for-each select="$refence.file/entry">
<xsl:if test="not(exists(//text()[ancestor::head][matches(.,
concat('(^|\W)(',current(),')($|\W)'))]))">
<xsl:message>
<xsl:value-of select="."/>
</xsl:message>
</xsl:if>
</xsl:for-each>
</xsl:template>
but this method tends to be rather slow when i have a reference file
that has many entries. Is there another way to go around this, by keys
maybe?
Thanks,
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--