• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to filter out some of the attributes?

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my XML, each element has, say 10 attributes.....but I want to print only some of them. How do I do that...
I do not want to say...
<xsl:value-of select="../@attrib1"/>
<xsl:value-of select="../@attrib2"/>
:
I want to be able to filter out saying something like
<xsl:if test!="attrib1|attrib2">
<xsl:value-of select="@attrib1"/>
</xsl:if>
My xml:
<?xml version="1.0"?>
<catalog>
<cd title="Empire Burlesque" artist="Bob Dylan" country="USA"
company="Columbia" price="10.90" year="1985"
</cd>
.
.
.
</catalog>
I want to print only the values of the following attributes
artist, Country, company.
This is just an example....actually I have something like 20 attributes but I need to print only some of them.
Thanks in advance.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bala, what exactly your filter is?
If you wantto test if an element has some attribute, you can use simply put it's name in a test expression - it means "exist".
For example:
<xsl:if test="catalog/cd/@country">
<xsl:value-of select="catalog/cd/@artist"/>
</xsl:if>
but I am not sure it is what you want.
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, say you wanted to print the title attribute only if artist and title were both defined. Then you would use
<xsl:template match="cd">
 <xsl:if test="@artist">
  <xsl:if test="@title">
   <xsl:value-of select="@title"/>
  </xsl:if>
 </xsl:if>
</xsl:template>
[ January 11, 2002: Message edited by: Geoffrey Falk ]
[ January 11, 2002: Message edited by: Geoffrey Falk ]
 
Look ma! I'm selling my stuff!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic