Created
February 19, 2021 21:29
-
-
Save emchateau/10397d9c65136919ff3b5dc66df040b7 to your computer and use it in GitHub Desktop.
getDeepest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*[not(*)][count(ancestor::node()) | |
= | |
max(//*[not(*)]/count(ancestor::node())) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:for-each-group select="//title" | |
group-by="count(ancestor::*)"> | |
<xsl:sort select="current-grouping-key()"> | |
<xsl:if test="position()=last()"> | |
<xsl:copy-of select="current-group()"/> | |
</if> | |
</sort> | |
</xsl:for-each-group> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
innermost(//*)[count(ancestor::node()) | |
= | |
max(//*[not(*)]/count(ancestor::node())) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:accumulator name="depth" initial-value="0, 0" as="xs:integer*"> | |
<xsl:accumulator-rule match="*" phase="start" | |
select=" | |
let $myDepth := head($value) + 1 | |
return | |
($myDepth, max(($myDepth, tail($value))))"/> | |
<xsl:accumulator-rule match="*" phase="end" | |
select=" | |
head($value) - 1, tail($value) | |
"/> | |
</xsl:accumulator> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:function name="re:find-spine" as="node()+"> | |
<xsl:param name="node" as="node()"/> | |
<xsl:variable name="end1" select="re:find-deepest($node) => path()"/> | |
<xsl:variable name="newTree" as="node()" select="$node => re:make-root($end1)"/> | |
<xsl:variable name="end2" as="node()" select="re:find-deepest($newTree)"/> | |
<xsl:sequence select="$end2/ancestor-or-self::*"/> | |
</xsl:function> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment