Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSL

 
Harsha Jay
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
 
Juan Rolando Prieur-Reza
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.
 
Hari Vignesh Padmanaban
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 !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic