Reputation: 815
This fragment of XML contains the elements sic
, del
, and surplus
to which I would like to add a count a, b, c
etc in a new attribute n
:
<body xmlns="http://www.tei-c.org/ns/1.0">
<ab>
<seg>Lorem<sic att="sictest1">sic <ref>1</ref> content</sic> ipsum dolor sit amet,
consectetur<del att="deltest1">del <ref>1</ref> content</del> adipiscing elit.
Sed elementum lorem ac purus<surplus att="surptest1">surplus <ref>1</ref>
content</surplus> bibendum, ut cursus sapien auctor. Nam lacinia ante in
ultricies ultrices. Pellentesque<surplus att="surptest2">surplus <ref>2</ref>
content</surplus> accumsan ligula<sic att="sictest2">sic <ref>2</ref>
content</sic> vitae facilisis mattis.</seg>
</ab>
</body>
However this XSL :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
version="3.0">
<xsl:output method="xml" indent="no"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!-- set letters to apparatus -->
<xsl:template match="tei:sic | tei:del | tei:surplus">
<xsl:variable name="fn">
<xsl:number count="." format="a" level="any"/>
</xsl:variable>
<xsl:variable name="name" select="name(.)"/>
<xsl:element name="{ $name }" namespace="http://www.tei-c.org/ns/1.0">
<xsl:copy-of select="@*"></xsl:copy-of>
<xsl:attribute name="n">
<xsl:value-of select="$fn"/>
</xsl:attribute>
<xsl:copy-of select="node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Is returning the XML below, where the values for attribute n
are h, n, t, z, af
:
<body xmlns="http://www.tei-c.org/ns/1.0">
<ab>
<seg>Lorem<sic att="sictest1" n="h">sic <ref>1</ref> content</sic> ipsum dolor sit amet,
consectetur<del att="deltest1" n="n">del <ref>1</ref> content</del> adipiscing elit.
Sed elementum lorem ac purus<surplus att="surptest1" n="t">surplus <ref>1</ref>
content</surplus> bibendum, ut cursus sapien auctor. Nam lacinia ante in
ultricies ultrices. Pellentesque<surplus att="surptest2" n="z">surplus <ref>2</ref>
content</surplus> accumsan ligula<sic att="sictest2" n="af">sic <ref>2</ref>
content</sic> vitae facilisis mattis.</seg>
</ab>
</body>
But I am expecting the following:
<body xmlns="http://www.tei-c.org/ns/1.0">
<ab>
<seg>Lorem<sic att="sictest1" n="a">sic <ref>1</ref> content</sic> ipsum dolor sit amet,
consectetur<del att="deltest1" n="b">del <ref>1</ref> content</del> adipiscing elit.
Sed elementum lorem ac purus<surplus att="surptest1" n="c">surplus <ref>1</ref>
content</surplus> bibendum, ut cursus sapien auctor. Nam lacinia ante in
ultricies ultrices. Pellentesque<surplus att="surptest2" n="d">surplus <ref>2</ref>
content</surplus> accumsan ligula<sic att="sictest2" n="e">sic <ref>2</ref>
content</sic> vitae facilisis mattis.</seg>
</ab>
</body>
Fiddle here.
Many thanks in advance.
Upvotes: 0
Views: 33
Reputation: 163418
The count
attribute is a pattern, which indicates which nodes should be counted. The value count="."
matches all nodes, so all nodes are counted. Try count="tei:sic | tei:del | tei:surplus"
.
Upvotes: 1