Here's a very simple method:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="ss:root/ss:wd[preceding-sibling::ss:wd[.='abc'] and following-sibling::ss:wd[.='def']]">
<xsl:value-of select="." />
<xsl:if test="position()!=last()">
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Note that it is assumed that the input here is in the form of:
<root xmlns="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd">
<wd>001</wd>
<wd>002</wd>
<wd>abc</wd>
<wd>123</wd>
<wd>456</wd>
<wd>789</wd>
<wd>def</wd>
<wd>998</wd>
<wd>999</wd>
</root>
Given this input, the result of applying the above transformation is:
123/456/789
You did not provide your (full) input or required output, so you will need to make the necessary adjustments.
IMPORTANT:
We are also assuming that there is only one occurrence of <wd>abc</wd>
and <wd>def</wd>
in the entire node-set. Otherwise it won't be that simple.
--
A note about performance: it is difficult to predict performance without testing it on the actual processor you will be using. In general, explicit code is faster than implied one: it's better to say ss:root/ss:wd
than //ss:wd
, and ss:wd
is preferable to *
.
Edit:
The structure of the document you have linked to is significantly different from the example in your question. Specifically, the <wd l="1675" t="4243" r="1939" b="4358">7BB</wd>
node has no following siblings, since it is the last child of its <ln>
parent. Note also that a <wd>
with a value of SHIPMENT
appears twice.
Nevertheless, I ran the following test stylesheet against it:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd"
exclude-result-prefixes="ss">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<test>
<xsl:for-each select="//ss:wd[preceding::ss:wd[.='7BB'] and following::ss:wd[.='SHIPMENT']]">
<wd>
<xsl:value-of select="." />
</wd>
</xsl:for-each>
</test>
</xsl:template>
</xsl:stylesheet>
and obtained the following result:
<?xml version="1.0" encoding="utf-8"?>
<test>
<wd>National</wd>
<wd>Distribution</wd>
<wd>Centre</wd>
<wd>Kelway</wd>
<wd>Ltd</wd>
<wd>Unit</wd>
<wd>19,</wd>
<wd>Glebe</wd>
<wd>Farm</wd>
<wd>Road</wd>
<wd>Glebe</wd>
<wd>Farm</wd>
<wd>Industrial</wd>
<wd>Estate</wd>
<wd>Rugby</wd>
<wd>CV21</wd>
<wd>1GQ</wd>
</test>
Hopefully, that's something you can work with.