Accessing ancestral data from currentElementLocation with XSLTOperation
Posted: Tue Mar 28, 2017 7:41 pm
I'm having trouble implementing an XSLTOperation for a custom framework. The purpose of this operation is to sort list items in an unordered list, according to linguistic collation rules. For this to function, I must access the document's @lang attribute, which resides on the root element. Code for the XSLT:
I'm not able to access the lang attribute that must be passed as a query parameter on the collationURI variable. I get a null return for that language value, so the collation fails (it collates, but without a valid language constraint, it fails to collate the text according to collation rules for that language). I recognize the need to pass the currentElementLocation parameter in order to access data in ancestral contexts from the selected list that's being transformed, but this is failing, and I'm using that technique to access the lang attribute. Any suggestions?
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" xmlns:lds="http://www.lds.org/schema/lds-meta/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs saxon" version="2.0">
<xsl:param name="currentElementLocation"/>
<xsl:template match="/">
<xsl:apply-templates select="saxon:eval(saxon:expression($currentElementLocation))"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ul">
<xsl:variable name="lang" select="//html/attribute::lang"/>
<xsl:variable name="collationURI">
<xsl:value-of select="concat('http://www.w3.org/2013/collation/UCA?lang=',$lang)"/>
</xsl:variable>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="li">
<xsl:sort collation="{$collationURI}" select="lds:get-sort-key-text(string-join(*[1][not(self::ul) and not(self::ol)]/descendant::text(),''))"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:function name="lds:get-sort-key-text">
<xsl:param name="input-text"/>
<xsl:value-of select="replace($input-text,'\p{P}','')"/>
</xsl:function>
</xsl:stylesheet>