1
votes

I have some XML

<p>Lorem ipsum dolor sit amet,<unclear reason="illegible"/> elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
quis nostrud exercitation ullamco laboris <unclear reason="illegible"/> ex ea 
commodo consequat. Duis aute irure dolor in reprehenderit in 
voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
<unclear reason="illegible"/> non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum</p>

When I try and run

<xsl:value-of select="/p" disable-output-escaping="yes"/> 

it doesn't return the xml tags. How can I include the tags in value-of query?

hat I would like it to include the whole text with something to identify the unclear tags in the text.

1

1 Answers

1
votes

That is correct, the value-of an element is, by definition, the concatenation of all its descendant text nodes. You can't "include the tags in value-of query" but you could use copy-of instead of value-of to copy the whole p element to the output, including its children (text nodes and elements)

<xsl:copy-of select="/p" />

or if you want the content of the p element but not the surrounding <p> and </p> tags (e.g. if you're inserting the content into another element) then

<xsl:copy-of select="/p/node()" />

If you want to convert the unclear elements to something else rather than including them as-is then you probably want to use an identity template based transformation instead

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- copy everything from input to output verbatim, except where
       a more specific template applies -->
  <xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
  </xsl:template>

  <!-- handle unclear elements differently -->
  <xsl:template match="unclear">
    <xsl:text>__UNCLEAR__</xsl:text>
  </xsl:template>
</xsl:stylesheet>

Given your sample input this would produce

<p>Lorem ipsum dolor sit amet,__UNCLEAR__ elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
quis nostrud exercitation ullamco laboris __UNCLEAR__ ex ea 
commodo consequat. Duis aute irure dolor in reprehenderit in 
voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
__UNCLEAR__ non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum</p>