Project

Profile

Help

filter with a function

Added by Anonymous almost 17 years ago

Legacy ID: #4463370 Legacy Poster: Maria Muslea (codra13)

Hi, I have some XML that contains something like: <A> .... <keyword>New York|Los Angeles|Detroit</keyword> </A> and I would like to filter all "A" that contain "New York" in the keyword (for example). Initially I only had one city in the keyword, so I was doing something like: let $a := $doc/A[keyword="New York"] but now I should use the contains() function ... somehow. I can't figure out how I can do this. Any help would be appreciated. Thank you, Maria


Replies (3)

Please register to reply

RE: filter with a function - Added by Anonymous almost 17 years ago

Legacy ID: #4464237 Legacy Poster: Colin Green (colgreen)

Hi Maria, I think you want something like this: A[keyword[contains(string(text()),"New York")]] Or actually you don't really need to explictly convert the text node to a string so you can just write: A/keyword[contains(text(),"New York")] Also a document can have only one root element so instead of this: $doc/A/keyword[contains(text(),"New York")] you probably want something like this: $doc/ROOT/X/Y/Z/A/keyword[contains(text(),"New York")] Hope this helps, Colin

RE: filter with a function - Added by Anonymous almost 17 years ago

Legacy ID: #4464322 Legacy Poster: Maria Muslea (codra13)

Thank you. I ended up using: A[keyword[contains(text(),"New York")]] because I wanted to filter te "A". I appreciate your help. Thank you, Maria

RE: filter with a function - Added by Anonymous almost 17 years ago

Legacy ID: #4464527 Legacy Poster: Michael Kay (mhkay)

Try $doc/A[tokenize(keyword, '|')="New York"] By the way, XSLT coding questions are better asked on the xsl-list at mulberrytech.com, if there is nothing specific to the Saxon product. Michael Kay Saxonica Limited

    (1-3/3)

    Please register to reply