xsl-list
[Top] [All Lists]

Aw: [xsl] Processing text nodes once

2015-10-08 15:01:16
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(_at_)rickquatro(_dot_)com" <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>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="" /> 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="" /> 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="" /> 25</a>.Paragraph content for Chapter 25.</p>
<p>Paragraph content for Appendix F.Paragraph content for <a
href="" /> F</a>.</p>
</root>

<Prev in Thread] Current Thread [Next in Thread>
  • Aw: [xsl] Processing text nodes once, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de <=