xsltlife
xsltlife

Reputation: 163

Use specific element for tab spaces

I want to use specific elements for tab spaces.

Input :

<table>
  <tr>
      <td>    noon   Nothing But Trailers MVLSC.</td>
  </tr>
  <tr>
      <td>   7.10   Between Worlds 16VLSC 2018 Thriller.</td>
  </tr>
</table>

Output should be:

<p type="Entry"><t/>noon<t/>Nothing But Trailers<char type="endNestedStyleHere"/> MVLSC.</p>

<p type="Entry"><t/>7.10<t/>Between Worlds<char type="endNestedStyleHere"/> 16VLSC 2018 Thriller.</p>

Tried code:

<xsl:template match="td[matches(.,'^\t*[0-9].*|\t*noon')]">
    <p type="Entry">
        <xsl:apply-templates/>
    <p>
</xsl:template>

<xsl:template match="td/text()">
    <xsl:if test="matches(.,'\t')">
        <t/>
    </xsl:if>
</xsl:template>

Upvotes: 0

Views: 103

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117100

How about:

<xsl:template match="td">
    <p type="Entry">
        <xsl:analyze-string select="." regex="\t">
            <xsl:matching-substring>
                <t/>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:analyze-string select="." regex=" (MVLSC|16VLSC|MSC|16VL|ML|MC|PGC)">
                    <xsl:matching-substring>
                        <char type="endNestedStyleHere"/>
                        <xsl:value-of select="." />
                    </xsl:matching-substring>
                    <xsl:non-matching-substring>
                        <xsl:value-of select="." />
                    </xsl:non-matching-substring>
                </xsl:analyze-string>                    
            </xsl:non-matching-substring>
        </xsl:analyze-string>                    
    </p>
</xsl:template>

Upvotes: 1

Related Questions