|
Subject: [xsl] Nodeset problem From: andy white <andy_p_white@xxxxxxxxxxx> Date: Fri, 20 Jul 2007 10:19:54 +0000 (GMT) |
Hi All,
Being new to xsl, this has me completly befuzzled - either that or my brain gave up and went on holiday! - so any help would be greatly appreciated.
I have an XML file that I'm parsing that has many entries of data. I can happily extract the data but I need to validate certain components of it.
The problem is that what I need to validate against is data contained within another file (containing lookup data if you like):
<Groups>
<Company ID='000011'>
<Foo ID='01234567'/>
<Foo ID='13123123'/>
<Foo ID='1232132'/>
<Foo ID='55534332'/>
</Company>
<Company ID='000131'>
<Foo ID='23423432'/>
<Foo ID='23236543'/>
<Foo ID='0043543'/>
</Company>
</Groups>
So, if I grab the string 0043543 from the original XML I need to compare it with the lookup to see if it exists. If it does then I do nothing, otherwise I record a failure entry. (The check should be against any company - it's simply to see if the string exists <anywhere> in the above file)
The stylesheet I'm calling with the original data is:
<xsl:variable name="lookupfile" select="lookup.xml'"/>
<xsl:variable name="foonodes" select="document($lookupfile)"/>
<xsl:key name="list" match="entry" use="Foo_Number"/>
<xsl:template match="/">
<FooValidator>
<xsl:for-each select="/doc/entry[generate-id(.)=generate-id(key('list',Foo_Number))]">
<xsl:variable name="foo" select="Foo_Number"/>
<!-- Call foocomparison to see if "foo" exists in lookup file (nodes) -->
<xsl:call-template name="foocomparison">
<xsl:with-param name="foo" select="$foo"/>
<xsl:with-param name="foolist" select="$nodes"/>
</xsl:call-template>
</xsl:for-each>
</FooValidator>
</xsl:template>
<xsl:template name="foocomparison">
<xsl:param name="foo" select="normalize-space(.)"/>
<xsl:param name="foolist"/>
<xsl:choose>
<!--
<xsl:when test="not(string-length($mid)=0) and $foolist[contains(.,$foo)]">
<xsl:text>Valid FOO</xsl:text>
</xsl:when>
<xsl:otherwise>
<Invalid>
<xsl:text>Error: FOO doesn't exist: </xsl:text>
<foo><xsl:value-of select="$mid"/></foo>
</Invalid>
</xsl:otherwise>
-->
<xsl:when test="not(string-length($foo)=0) and contains($foolist,$foo)">
<xsl:text>Valid FOO</xsl:text>
</xsl:when>
<xsl:otherwise>
<Invalid>
<xsl:text>Error : FOO doesn't exist </xsl:text>
<foo><xsl:value-of select="$foo"/></foo>
</Invalid>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
But this just always gives me Error:... even if the value I pass in exists anywhere in the lookup file :(
I'm guessing that the $nodes variable is rubbish and not doing what I think it should?
Is this complete nonsense? Or am I going insane? Laaaa la la de dee di dum - yup :)
Thanks All,
Andy
___________________________________________________________
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Select the nearest of two, Michael Kay | Thread | RE: [xsl] Nodeset problem, Michael Kay |
| RE: [xsl] Select the nearest of two, Michael Kay | Date | Re: [xsl] PI for associating a samp, George Cristian Bina |
| Month |