Subject: Re: [xsl] Processing text nodes once From: "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 8 Oct 2015 20:09:43 -0000 |
Hi Martin, Yes, that was the problem. Here is the solution using the nesting: <!-- 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: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:non-matching-substring> </xsl:analyze-string> </xsl:template> Rick From: Martin Honnen martin.honnen@xxxxxx [mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx] Sent: Thursday, October 08, 2015 4:01 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Aw: [xsl] Processing text nodes once I think the problem is that you have two analyze-string inside the template for text nodes, that way you process each content twice. You might need to nest them, i.e put one of them into the non-matfhing-substring clause of the other. -- Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet. "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>schrieb: 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 EasyUnsubscribe (by email)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Aw: [xsl] Processing text nodes onc, Martin Honnen martin | Thread | [xsl] xsl:with-param focus, Martynas Jusevičius |
Aw: [xsl] Processing text nodes onc, Martin Honnen martin | Date | [xsl] xsl:with-param focus, Martynas Jusevičius |
Month |