Project

Profile

Help

Iterate through node-set. Help...

Added by Anonymous over 16 years ago

Legacy ID: #4679731 Legacy Poster: geek.shrek (geek-shrek)

Hi, I'm trying to create XSLT that iterate through node-set like a for loop and when i found a match then apply templates or return value. or is there any function to check if my value exist in a node-set? Here's my xml data: <?xml version="1.0" encoding="UTF-8"?> <Books> <Book name="ABC"> <Date real="yes">2007/12/10</Date> <Date real="no">2007/13/10</Date> <Date real="no">2007/14/10</Date> <Date real="no">2007/15/10</Date> <Date real="no">2007/16/10</Date> <Date real="no">2007/12/17</Date> <Date real="no">2007/18/10</Date> </Book> <Book name="DEF"> <Date real="no">2007/12/10</Date> <Date real="no">2007/13/10</Date> <Date real="no">2007/14/10</Date> <Date real="yes">2007/15/10</Date> <Date real="no">2007/16/10</Date> <Date real="no">2007/17/10</Date> <Date real="yes">2007/18/10</Date> </Book> </Books> I need to know if my value is exist on Date element. eg. I have tmp="2007/12/17". I need to check if 'tmp' exist in Book[name="ABC"] and return the value real. I wonder if someone can help me or point me to a good tutorial. Thanks,


Replies (1)

RE: Iterate through node-set. Help... - Added by Anonymous over 16 years ago

Legacy ID: #4680481 Legacy Poster: Freek Segers (freeksegers)

Hi, I would recommend reading some XPath tutorial. Just google "xpath tutorial" and you'll find a whole bunch of them. The XPath for your problem would be Book[name="ABC"][Date/text() eq $tmp] if $tmp contains the date you are looking for. In XSLT this can be tested with: <xsl:if test="Book[name="ABC"][Date/text() eq $tmp]"> <your-elements/> </xsl:if> Hope this helps.

    (1-1/1)

    Please register to reply