0

Below my input

<root>
<text>
 <bold>Co<csc>lorado DivIs</csc>IoN</bold>
</text>
<text>
 fi<csc>ve and a ha</csc>lf <x>abc</x>
</text>
</root>

Here is my xslt my implemntation (xslt verions-1.0)

<xsl:for-each select="/root/text">
    <xsl:value-of select="./child::*[local-name(.)!='x']" />
  <xsl:text> </xsl:text>
</xsl:for-each>

correct output look like below, should ignore only 'x' element value.

Colorado DivIsIoN five and a half

The output I am getting is with missing current element text.

 Colorado DivIsIoN ve and a ha

2 Answers2

2

Try it this way?

<xsl:template match="/">
    <xsl:for-each select="root/text">
        <xsl:for-each select=".//text()[not (parent::x)]">
            <xsl:value-of select="." />
        </xsl:for-each>
        <xsl:text> </xsl:text>
    </xsl:for-each>
</xsl:template>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
0

try this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="UTF-8" indent="yes"/>
    <xsl:template match="root">

      <xsl:apply-templates select="@*|node()"/>

  </xsl:template>

  <xsl:template match="text/x"/>

  <xsl:template match="@* | node()">

      <xsl:apply-templates select="@* | node()"/>

  </xsl:template>

<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template> 

</xsl:stylesheet>
user2423959
  • 836
  • 1
  • 13
  • 27
  • You have four templates; two of them don't do anything. – michael.hor257k Feb 28 '14 at 08:03
  • first to match root, second to ignore x, third to match node and 4th just to get text. lease let me know if i'm making any flaw in writing code like this, as i'm not that proficient in XSLT. Thanks – user2423959 Feb 28 '14 at 08:30
  • 1
    Root is a node, so it is already matched by the third template. And the third template does not output anything. Your second and fourth templates are doing all the work here. – michael.hor257k Feb 28 '14 at 11:02