Subject: RE: [xsl] Nodeset problem From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Sat, 21 Jul 2007 19:16:10 +0100 |
I suspect the code you posted isn't the code you executed (variables $nodes is undeclared - perhaps $foonodes intended???) - which means that it's difficult to distinguish your real error from any typos introduced in the transcription process. But I'm suspicious of contains($foolist,$foo) - I suspect you're falling into the trap of imagining that contains() tests whether a set of values contains a value. It actually tests whether a string contains a substring. You probably just want ($foolist = $foo). But the whole lookup would be better done using keys. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: andy white [mailto:andy_p_white@xxxxxxxxxxx] > Sent: 20 July 2007 11:20 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Nodeset problem > > 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_N > umber))]"> > <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/mai > l/winter07.html
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Nodeset problem, andy white | Thread | [xsl] Group consecutive elements ba, Kevin Bird |
Re: [xsl] Finding the ID attribute , v vijith | Date | RE: [xsl] Vendor extensions for XSL, Justin Johansson |
Month |