Thanks for the help.
Code:
<xsl:variable name="curID" select="ancestor::*[@id][1]/@id"/>
This returns the first <indxref> ancestor::*[@id][1]/@id. Below is a working example.
Current output:
Code:
<out xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<result>title</result>
<result>title</result>
</out>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<chapter id="chapter1">
<title id="title">
<indxref indxlevel1="Stopping Procedures">
<pcnarr>STOPPING PROCEDURE</pcnarr>
</indxref>
<indxref indxlevel1="Procedures, Stopping">
<pcnarr/>
</indxref>
</title>
</chapter>
<chapter id="chapter2">
<title id="title2">
<indxref indxlevel1="Procedures">
<pcnarr> PROCEDURE</pcnarr>
</indxref>
<indxref indxlevel1="Procedures, running">
<pcnarr/>
</indxref>
</title>
</chapter>
</root>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<out>
<xsl:for-each-group select="//indxref" group-by="substring(@indxlevel1, 1,1)">
<xsl:sort select="current-grouping-key()" order="ascending"/>
<xsl:variable name="curID" select="ancestor::*[@id][1]/@id"/>
<result>
<xsl:value-of select="$curID"/>
</result>
</xsl:for-each-group>
</out>
</xsl:template>
</xsl:stylesheet>
I am using saxon 9.1.0.5
My desired result would be:
Code:
<out xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<result>title</result>
<result>title</result>
<result>title2</result>
<result>title2</result>
</out>