Hi,
Iam not sure if you can get a list of all possible XPATH from an
XML document. But Dimitre has written a stylesheet that will print atleast
one valid xpath for all elements and attributes. The stylesheet is as
follows:
<!-- xsl for getting xpath for a node BEGIN -->
<xsl:variable name="theNode" select="."/>
<xsl:for-each select="$theNode
$theNode/ancestor-or-self::node()[..]">
<xsl:element name="slash">/</xsl:element>
<xsl:choose>
<xsl:when test="self::*">
<xsl:element name="nodeName">
<xsl:value-of select="name()"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::*[name(current()) =
name()])"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::*[name(current()) =
name()])"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select="concat('[', $thisPosition +
1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:otherwise> <!-- This node is not an element -->
<xsl:choose>
<xsl:when test="count(. | ../@*) = count(../@*)">
<!-- Attribute -->
<xsl:element name="nodeName">
<xsl:value-of select="concat('@',name())"/>
</xsl:element>
</xsl:when>
<xsl:when test="self::text()"> <!-- Text -->
<xsl:element name="nodeName">
<xsl:value-of select="'text()'"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::text())"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::text())"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select="concat('[', $thisPosition +
1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="self::processing-instruction()">
<!-- Processing Instruction -->
<xsl:element name="nodeName">
<xsl:value-of select="'processing-instruction()'"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::processing-instruction())"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::processing-instruction())"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select="concat('[', $thisPosition +
1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="self::comment()"> <!-- Comment -->
<xsl:element name="nodeName">
<xsl:value-of select="'comment()'"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::comment())"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::comment())"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select="concat('[', $thisPosition +
1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<!-- Namespace: -->
<xsl:when test="count(. ../namespace::*) =
count(../namespace::*)">
<xsl:variable name="apos">'</xsl:variable>
<xsl:element name="nodeName">
<xsl:value-of select="concat('namespace::*',
'[local-name() = ', $apos, local-name(), $apos, ']')"/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:text>
</xsl:text>
<!-- xsl for getting xpath for a node END -->
I remember seeing that this works only with the MSXML3 parser. You may have
to get somebody's help to port this to other processors.
Cheers,
Omprakash.V
"Michael Lindenau
(geschäftlich)" To:
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
<michael(_dot_)lindenau(_at_)loesungen-und cc:
(bcc: omprakash.v/Polaris)
-ideen.de> Subject: [xsl]
How to get a list of XPath out of XML schema
documents
02/24/2005 08:10 AM
Please respond to xsl-list
Hi,
I'm a newbie and I would like to figure out, how I can get a list of all
XPath in an XML document via XLST.
The list can have XML, HTML or CSV format. I'm only interested in all
complete XPath expressions.
Something like
/doc/main/field
/doc/main/field/id
...
Are examples somewhere available. I searched through Google all night
long with little success.
Thanx in advance for any help
--
Kind regards
Michael Lindenau
Lösungen+Ideen
"Any problem in computer science can be solved with
another layer of indirection. But that usually will
create another problem!" <David Wheeler>
mobile: +49 (0) 179 29 28 834
e-mail: michael(_dot_)lindenau(_at_)loesungen-und-ideen(_dot_)de
-------------------------------------------------------
Lösungen+Ideen
Alejandro Puskin No 1, Portal H, 5C
29011 Málaga
ES - España
-------------------------------------------------------
This email is confidential. If you are not the intended
recipient, you must not disclose or use the information
contained in it. If you have received this mail in error,
please tell me immediately by return email and delete
the document.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
This e-Mail may contain proprietary and confidential information and is sent
for the intended recipient(s) only.
If by an addressing or transmission error this mail has been misdirected to
you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction,
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its
attachment other than by its intended recipient/s is strictly prohibited.
Visit Us at http://www.polaris.co.in
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--