• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSLT select question

 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all:
Is it possible to select a range of node using XSLT, for example, for the following XML:
<test>
<scan>1</scan>
<scan>2</scan>
<scan>3</scan>
<scan>4</scan>
<scan>5</scan>
</test>
How to select all scan element with text value less than 4. In other word, I want to select
<scan>1</scan>
<scan>2</scan>
<scan>3</scan>
by knowing incoming parameter value as 4.
Any help, thanks in advance.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The first template generates the outer <test> element -- without this, the output would not be well-formed XML since it would contain multiple <scan> elements at the root level.
The second template matches each <scan> element whose text value is less than 4. Note that in the predicate expression, I had to escape the less-than sign as &lt; since "<" isn't allowed in an XML attribute value.
The third template suppresses the default action of printing out the text value of all nodes.
[ November 12, 2002: Message edited by: Ron Newman ]
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Ron:
Thank you very much for your reply!!! I think your method works to my above example. Can I further ask another question, is it possible if the value is not merely number, like the following:
To select from:
<test>
<scan>1a</scan>
<scan>2a</scan>
<scan>3a</scan>
<scan>4a</scan>
<scan>5a</scan>
</test>
to get the following:
<test>
<scan>1a</scan>
<scan>2a</scan>
<scan>3a</scan>
</test>
using 4a as the criteria?
Thanks again for your reply!
guoqiao
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to precisely define the format of that string, and then use the substring(), substring-before(), substring-after(), translate(), string-length(), and/or contains() functions to extract the numeric information from it.
[ November 12, 2002: Message edited by: Ron Newman ]
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Ron:
Thank you very much! I think I got very helpful hint from your words.
Thanks again and have a nice day there!!!
Guoqiao

Originally posted by Ron Newman:
You'll need to precisely define the format of that string, and then use the substring(), substring-before(), substring-after(), translate(), string-length(), and/or contains() functions to extract the numeric information from it.
[ November 12, 2002: Message edited by: Ron Newman ]

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic