H725
H725

Reputation: 17

XSL erase part of text maintain inner html tags

I have some XML like this:

<div id="Testo" class="Paragrafo">

<p class="numero">Numero 1</p>

<p class="rubrica"><em>(Prova)</em></p>

<p class="Paragrafo"><span class="tt">1. Un, due, tre:
la Peppina la fa il caffè, fa il caffè con la <strong>cioccolata</strong>, la Peppina l’è malata, ma malata no, non è, sol per <em>prendere</em> il caffè! E la mamma, che lo sa, il <em>caffè</em> non glielo dà.</span></p>

<p class="Paragrafo"><span class="tt">2. Un, due, tre:
la Peppina la fa il caffè, fa il caffè con la <strong>cioccolata</strong>, la Peppina l’è malata, ma malata no, non è, sol per <em>prendere</em> il caffè! E la mamma, che lo sa, il <em>caffè</em> non glielo dà.</span></p>

</div>

I want to do this:

<div id="Testo" class="Paragrafo">

<p class="numero">Numero 1</p>

<p class="rubrica"><em>(Prova)</em></p>

<p class="Paragrafo"><span class="tt">Un, due, tre:
la Peppina la fa il caffè, fa il caffè con la <strong>cioccolata</strong>, la Peppina l’è malata, ma malata no, non è, sol per <em>prendere</em> il caffè! E la mamma, che lo sa, il <em>caffè</em> non glielo dà.</span></p>

<p class="Paragrafo"><span class="tt">Un, due, tre:
la Peppina la fa il caffè, fa il caffè con la <strong>cioccolata</strong>, la Peppina l’è malata, ma malata no, non è, sol per <em>prendere</em> il caffè! E la mamma, che lo sa, il <em>caffè</em> non glielo dà.</span></p>

</div>

here is problem. Using XSLT i want same text but i must erase number and poit at begginning of text. If i use substring, lose every html inner tags as em strong ecc but text remain. I want maintains html tags with inner text

thanks!

Upvotes: 0

Views: 22

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116959

An example does not expound the rule. Here you could get the expected result* using:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="span[@class='tt']/text()[1]">
    <xsl:value-of select="substring-after(., '. ')"/>
</xsl:template>

</xsl:stylesheet>

Whether that would fit all your cases is not clear.


(*) Provided you fix your input to be well-formed XML: <strong> does not match </Strong>.

Upvotes: 1

Related Questions