Xsl: copy of exclusive parent
What code can I use instead of <xsl:copy-of select="tag"/> , which applies to the next xml ..
<tag> content <a> b </a> </tag> .. would give the following result :?
content <a> b </a> I want to highlight all the content in it, but excluding the parent tag
Basically I have several sections of content in my XML file, formatted in html, grouped into xml tags
I want them to have conditional access to them and echo them For example: <xsl:copy-of select="description"/>
The created additional parent tags do not affect the rendering of the browser, but they are invalid tags, and I would prefer to remove them. Am I really not quite right about this?
Since you want to include the content part, you will need the node() function, not the * operator:
<xsl:copy-of select="tag/node()"/> I tested this with input and the result is the result:
content <a> b </a> Without hard coding, the root name of the node can be:
<xsl:copy-of select="./node()" /> This is useful in situations where you are already processing the root directory of a node and want to get an exact copy of all the elements inside, excluding the root of the node. For example:
<xsl:variable name="head"> <xsl:copy-of select="document('head.html')" /> </xsl:variable> <xsl:apply-templates select="$head" mode="head" /> <!-- ... later ... --> <xsl:template match="head" mode="head"> <head> <title>Title Tag</title> <xsl:copy-of select="./node()" /> </head> </xsl:template> In addition to Welbog's answer, which has my vote, I recommend writing separate templates according to this:
<xsl:template match="/"> <body> <xsl:apply-templates select="description" /> </body> </xsl:template> <xsl:template match="description"> <div class="description"> <xsl:copy-of select="node()" /> </div> </xsl:template>