[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Nodeset problem

Subject: Nodeset problem
From: andy white <andy_p_white@xxxxxxxxxxx>
Date: Fri, 20 Jul 2007 10:19:54 +0000 (GMT)
 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_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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.