|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Comma Separated Values - XSLT1.0
Hi Allan,
Of course, you could simplify the problem by first converting your input to something more XMLish:I have 2 XML elements each containing comma separated values. I need to take each individual value from <elem2> and see if it exists in <elem1>. If true is returned, go off and do something..... otherwise get the next value from <elem2> and compare it to all the values in <elem1> etc etc. <data>
<elem1>
<e>bloggs</e>
<e>smith</e>
<e>jones</e>
<e>bush</e>
<e>howard</e>
<e>bennis</e>
</elem1>
<elem2>
<e>skeen</e>
<e>seinfield</e>
<e>longshaw</e>
<e>bloggs</e>
<e>keitel</e>
</elem2>
</data>With Jarno's tokenizer template you could generate such an intermediate file and then take that as input for a second transform: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:key name="e1" match="elem1/e" use="."/> <xsl:template match="/*"> <result> <xsl:apply-templates select="elem2/e"/> <xsl:if test="not(elem1/e = elem2/e)"><not-found/></xsl:if> </result> </xsl:template> <xsl:template match="elem2/e"> <xsl:apply-templates select="key('e1',.)"/> </xsl:template> <xsl:template match="elem1/e"> <found><xsl:value-of select="."/></found> </xsl:template> </xsl:stylesheet> that would give <found>bloggs</found> (or <not-found/> if nothing is found). Note: test="not(elem1/e = elem2/e)" does not mean "the node-sets elem1/e and elem2/e are different", but "there is no elem1/e element that has the same string value as any elem2/e element". HTH, Anton
|
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
|

Cart








