• 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

XSL

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say something like this below

Does the apply-templates apply to all nodes including comment(), text() and PI's automatically? Or do we specifically have to mention those node types.
appreciate a response
-Harsha
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Harsha Jay:
<xsl:template match="//someNode">


Harsha,
I believe the "//" in the match is an erroneous use of XPath here. It does not make sense to say that the template will match someNode anywhere at or below the context in which this template may be applied. To match someNode at or below a certain context, you should use XPath in an expression within the body of a template.
Caveat Emptor: I am not an expert on XSL, but I am putting forth this answer with the expectation that someone who does know more will affirm or refute these assertions.
 
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harsha,
The code
<xsl:template match="//someNode">
<xsl:apply-templates select="*|@*"/>
</xsl:template>
Will select only the children nodes and the attributes of someNode. It WILL NOT selct the PI's and comments.
If you need to select these nodes, you would have to use special node tests for them. these are given below
comment()
processing-instruction()
text()
So to get everything , the code woudl be
<xsl:template match="//someNode">
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text
()"/>
</xsl:template>
Hope this helps
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note,
you dont have to use comment()* or processing-instruction()*.
The comment() itself will be suficient to let the XSLT processor to display all teh comment instructions under the required node!!
this is true for PI and text nodes also !!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic