xsl-list
[Top] [All Lists]

[xsl] Processing text nodes once

2015-10-08 14:46:47
Hello all,

I have a situation where I want to process the text nodes in my document to
add some linking. I am using <xsl:analyze-string> which works well. However,
I am getting duplicate text nodes in the output. I am thinking I am getting
into default template rules, but I am missing something conceptually. Any
help would be appreciated.

Rick

Input:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <title id="i12345">The document's title</title>
    <p>Paragraph content for Chapter 25.</p>
    <p>Paragraph content for Appendix F.</p>
</root>

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0">
    
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
   
    <!-- Non-live cross-references. -->
    <xsl:template match="text()">
        <xsl:analyze-string select="."
regex="Chapters?.(22|24|25|26|27|28|29|30|31|32|33|34)" flags="s">
            <xsl:matching-substring><a
href="../../s9ml/reader_2.html#fc123c86410d4d13a50755a2b9463bb8"><xsl:value-
of select="."/></a></xsl:matching-substring>
            <xsl:non-matching-substring><xsl:value-of
select="."/></xsl:non-matching-substring>
        </xsl:analyze-string>
        <xsl:analyze-string select="." regex="Appendix.[F-N]">
            <xsl:matching-substring><a
href="../../s9ml/reader_3.html#fea471a337cb44e9891bce483fad52dc"><xsl:value-
of select="."/></a></xsl:matching-substring>
            <xsl:non-matching-substring><xsl:value-of
select="."/></xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>
  
    <!-- Identity transform -->
    <xsl:template match="element()">
        <xsl:element name="{local-name(.)}">
            <xsl:apply-templates select="@*,node()"/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="attribute()">
        <xsl:copy/>
    </xsl:template>
    
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <title id="i12345">The document's titleThe document's title</title>
   <p>Paragraph content for <a
href="../../s9ml/reader_2.html#fc123c86410d4d13a50755a2b9463bb8">Chapter
25</a>.Paragraph content for Chapter 25.</p>
   <p>Paragraph content for Appendix F.Paragraph content for <a
href="../../s9ml/reader_3.html#fea471a337cb44e9891bce483fad52dc">Appendix
F</a>.</p>
</root>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Processing text nodes once, Rick Quatro rick(_at_)rickquatro(_dot_)com <=