• 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

Transforming to HTML using XSLT

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I ingore tags using xslt.
Suppose I need to display the <xsl: text> and the value depending on whether the tag is present or not?
For example:
<record>
<school>UNIVERSITY OF TEXAS</school>
<highschool>AUSTIN HIGH<highschool>
</record>
I display in HTML as
School: UNIVERSITY OF TEXAS
High School: AUSTIN HIGH
But there are some <record> tags where <school> maynot be present. So depending on whether the <school> tag is present I want to display or not display the School: UNIVERSITY OF TEXAS.

Thank you.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<xsl:if test="/record/school">
   Display the school name
</xsl:if>

Use this construct to test if the school element has a value of not.
To be more precise you could use string-length and (truncate? forgot the name of) the function that collapses the white-space.

- m
 
vivek ja
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Madhav, Thats exactly what I was looking for!
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The function to trim spaces is

string normalize-space(string)

This removes preceding and trailing spaces... and if more than one space is embedded then it reduces it to single space.

E.g. normalize-space(' Java Ranch ') returns 'Java Ranch'
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic