This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

XSL

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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 !!!
 
I can't take it! You are too smart for me! Here is the tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic