xsl processor: Saxon 8B
xsl version 2.0
Here is my test case:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<div1><!--Article-->
<ptr target="ids.27.3.1fm" n="10"/>
<ptr target="ids.27.3.2fm" n="11"/>
<div2><!--Subsection-->
<ptr target="ids.27.3.3fm" n="12"/>
<ptr target="ids.27.3.4fm" n="13"/>
</div2>
<div2><!--Notes-->
<ptr target="ids.27.3.1tm" n="10"/>
<ptr target="ids.27.3.2tm" n="11"/>
<ptr target="ids.27.3.3tm" n="12"/>
<ptr target="ids.27.3.4tm" n="13"/>
</div2>
</div1>
<div1><!--Article-->
<ptr target="ids.27.3.3fm" n="14"/>
<ptr target="ids.27.3.4fm" n="15"/>
<div2><!--Notes-->
<ptr target="ids.27.3.3tm" n="14"/>
<ptr target="ids.27.3.4tm" n="15"/>
</div2>
</div1>
<test><ptr/></test>
</root>
Here's my 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="no" encoding="utf-8" media-type="text/xml"
doctype-public="-//TEI P4//DTD Main Document Type//EN"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template
match="ptr[matches(@target,'([a-z]{3})\.([0-9]+)\.([0-9s]+)\.([0-9]+)[tf]m+?')]">
<xsl:choose>
<xsl:when
test="matches(@target,'([a-z]{3})\.([0-9]+)\.([0-9s]+)\.([0-9]+)[f]m+?')">
<ptr target="{(_at_)target}" n="{count(.|preceding::ptr)}"/>
</xsl:when>
<xsl:otherwise>
<ptr target="{(_at_)target}"
n="{count(.|preceding-sibling::ptr)}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
For my output, I get:
<?xml version="1.0" encoding="utf-8"?><root>
<div1><!--Article-->
<ptr target="ids.27.3.1fm" n="1"/>
<ptr target="ids.27.3.2fm" n="2"/>
<div2><!--Subsection-->
<ptr target="ids.27.3.3fm" n="3"/>
<ptr target="ids.27.3.4fm" n="4"/>
</div2>
<div2><!--Notes-->
<ptr target="ids.27.3.1tm" n="1"/>
<ptr target="ids.27.3.2tm" n="2"/>
<ptr target="ids.27.3.3tm" n="3"/>
<ptr target="ids.27.3.4tm" n="4"/>
</div2>
</div1>
<div1><!--Article-->
<ptr target="ids.27.3.3fm" n="9"/>
<ptr target="ids.27.3.4fm" n="10"/>
<div2><!--Notes-->
<ptr target="ids.27.3.3tm" n="1"/>
<ptr target="ids.27.3.4tm" n="2"/>
</div2>
</div1>
<test><ptr/></test>
This not quite what I want. In the second <div1>, I want the first two
@n values to be "1" and then "2", to match the markers in "Notes". The
preceding axis is too permissive, and preceding-sibling doesn't get me
there either, since for what I want, it doesn't track how @target
values with an "fm" in them are nested. I'm stumped. Any suggestions?
This list has been a great resource for me. I really appreciate your
help and attention!
Tony
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--