[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Processing text nodes once

Subject: Re: Processing text nodes once
From: "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 8 Oct 2015 19:56:00 -0000
Re:  Processing text nodes once
OK, I see it. I have two <xsl:analyze-string> elements both outputting
something. Sorry for the list noise.

-----Original Message-----
From: Rick Quatro rick@xxxxxxxxxxxxxx
[mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx] 
Sent: Thursday, October 08, 2015 3:47 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Processing text nodes once

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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.