As title
I am resarch xmlstartle, but seems no way to serach value from root node then return XPATH Is any idea?
ThanksPeter
As title
I am resarch xmlstartle, but seems no way to serach value from root node then return XPATH Is any idea?
ThanksPeter
Perhaps you can make use of this example which handles elements and attributes but not other node types. Assuming a POSIX shell, indentation and line continuation characters added for readability.
xmlstarlet select --text -t \
-m '//xsl:*/@test[contains(.,"position")]' \
-m 'ancestor-or-self::*' \
--var pos='1+count(preceding-sibling::*[name() = name(current())])' \
-v 'concat("/",name(),"[",$pos,"]")' \
-b \
--if 'count(. | ../@*) = count(../@*)' \
-v 'concat("/@",name())' \
-b \
-n \
/usr/share/*/xslt/docbook/common/db-common.xsl
Where:
-m (--match)
option specifies the target, with optional
search conditions given as
predicates-m (--match)
builds the XPath of elements from root to target,
calculating position by counting siblingsancestor-or-self::*
-
the -i (--if)
clause adjusts the XPath-C (--comp)
option before -t
lists the generated XSLT codeOutput:
/xsl:stylesheet[1]/xsl:template[2]/xsl:for-each[1]/xsl:if[1]/@test
/xsl:stylesheet[1]/xsl:template[3]/xsl:for-each[1]/xsl:if[1]/@test
/xsl:stylesheet[1]/xsl:template[7]/xsl:for-each[1]/xsl:choose[1]/xsl:when[1]/@test
/xsl:stylesheet[1]/xsl:template[7]/xsl:for-each[1]/xsl:choose[1]/xsl:when[3]/@test
Output from outer -m '//xsl:param[string(@select)]'
:
/xsl:stylesheet[1]/xsl:template[1]/xsl:param[1]
/xsl:stylesheet[1]/xsl:template[4]/xsl:param[1]
/xsl:stylesheet[1]/xsl:template[5]/xsl:param[1]
/xsl:stylesheet[1]/xsl:template[5]/xsl:param[2]
/xsl:stylesheet[1]/xsl:template[6]/xsl:param[1]