|
Subject: [xsl] grouping duplicate links with xslt 1.0 From: Terry Ofner <tdofner@xxxxxxxxx> Date: Fri, 21 Oct 2011 10:11:38 -0400 |
I couldn't find any reference to this issue in the archive. If it has been
addressed before, please forgive.
I have an issue with MS Word outputting duplicate links in xml, breaking up
the text. I need to group identical links and output one link while leaving
all other nodes/text the same. Here is an example of the input xml:
<paragraphs>
<!-- Have students practice [the activity in 9.01].-->
<p>Have students practice
<internalLink>
<target>Update_Link [7] [act_1]</target>the activity</internalLink>
<internalLink>
<target>Update_Link [7] [act_1]</target> in 9.01</internalLink>.</p>
<!-- Have students practive [the activity in 9.02]. -->
<p>Have students practice <internalLink>
<target>Update_Link [7] [act_2]</target>the activity</internalLink>
<internalLink>
<target>Update_Link [7] [act_2]</target> in 9.02</internalLink>.</p>
</paragraphs>
I am limited to xslt 1.0. The following 1.0 sheet does everything I need it to
except it drops the final period.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- duplicate link processor -->
<xsl:output method="xml" indent="yes"/>
<xsl:key name="link_target" match="internalLink" use="target" />
<xsl:template match="paragraphs">
<xsl:for-each select="p">
<p><xsl:apply-templates select="./text()[1]"/><internalLink>
<target><xsl:apply-templates select="internalLink[count(. |
key('link_target', target)[1]) = 1]/target"/></target>
<xsl:apply-templates
select="./internalLink/text()"/></internalLink></p></xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Here is the output using Oxygen/Saxon 6.5.5. Everything is good except for the
final period.
<?xml version="1.0" encoding="utf-8"?>
<p>Have students practice
<internalLink>
<target>Update_Link [7] [act_1]</target>
the activity
in 9.01</internalLink>
</p>
<p>Have students practice <internalLink>
<target>Update_Link [7] [act_2]</target>
the activity
in 9.02</internalLink>
</p>
Any pointers would be most appreciated.
Terry
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XML to XML change, handli, Ruud Grosmann | Thread | Re: [xsl] grouping duplicate links , Brandon Ibach |
| Re: [xsl] XSLT vs Schematron Decisi, Philip Fearon | Date | Re: [xsl] grouping duplicate links , Brandon Ibach |
| Month |