Thanks Michael and Erwan. I got the logic and works fine .
On 11/9/2010 2:44 PM, Michael Kay wrote:
For the first form, try
<xsl:for-each select="//*">
<xsl:value-of select="string-join(ancestor-or-self::*/name(), '/')"/>
</xsl:for-each>
For the second, try
<xsl:for-each select="//*">
<xsl:value-of select="string-join(ancestor-or-self::*/concat(name(),
string-join(@*/concat('[@', name(), ']'), '')),/')"/>
</xsl:for-each>
Not tested and almost certainly needs the punctuation adjusting.
Michael Kay
Saxonica
On 09/11/2010 06:44, Ramkumar.V wrote:
Hi, List
How to get complete XPATH from XML file as shown below? I am using
xslt2.0with saxon9?
Input XML:
========
<?xml version="1.0" encoding="utf-8"?>
<quizzes>
<quiz id="Q1.1" title="Biochemistry 1.1 Quiz" maxQuestions="4">
<question id="quiz1_1_question1" type="mc">
<prompt>1. Biochemistry is based on the chemistry of which
element?</prompt>
<option id="0">Hydrogen</option>
<option id="1">Oxygen</option>
<option id="2" correct = "true">Carbon</option>
<option id="3">Sulfur</option>
<feedback id="0">Incorrect.</feedback>
<feedback id="1">Incorrect.</feedback>
<feedback id="2">Correct!</feedback>
<feedback id="3">Incorrect.</feedback>
</question>
</quiz>
</quizzes>
Expected Output 1(Only Nodes):
=========================
quizzes
quizzes/quiz
quizzes/quiz/question
quizzes/quiz/question/prompt
quizzes/quiz/question/option
quizzes/quiz/question/option
quizzes/quiz/question/option
quizzes/quiz/question/option
quizzes/quiz/question/feedback
quizzes/quiz/question/feedback
quizzes/quiz/question/feedback
quizzes/quiz/question/feedback
Expected Output 2 (With Attributes):
============================
quizzes
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/prompt
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id]
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id]
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id][@correct='true']
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id]
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id='0']
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id='1']
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id='2']
quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id='3']
XSLT tried:
=========
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0" >
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="descendant-or-self::node()">
<xsl:value-of select="local-name()"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Regards,
Ramkumar V
===========================================================
***Disclaimer***
This email, and any attachments ("this email"), is confidential. If
you are not the addressee please tell the sender immediately, and
destroy this email without using, sending or storing it. Any
opinions, express or implied, in this email, are those of the sender,
and are not necessarily approved by the company. Except as expressly
stated, this e-mail should not be regarded as an offer, solicitation,
recommendation or agreement to buy or sell products or services, or
to enter into any contract. E-mail transmissions are not secure and
may suffer errors, viruses, delay, interception and amendment. The
company does not accept liability for damage caused by any of the
foregoing.
ALL INCOMING AND OUTGOING MAILS MAY BE MONITORED BY THE COMPANY.
============================================================
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--
===========================================================
***Disclaimer***
This email, and any attachments ("this email"), is confidential. If you are not
the addressee please tell the sender immediately, and destroy this email without using,
sending or storing it. Any opinions, express or implied, in this email, are those of the
sender, and are not necessarily approved by the company. Except as expressly stated,
this e-mail should not be regarded as an offer, solicitation, recommendation or agreement
to buy or sell products or services, or to enter into any contract. E-mail transmissions
are not secure and may suffer errors, viruses, delay, interception and amendment. The
company does not accept liability for damage caused by any of the foregoing.
ALL INCOMING AND OUTGOING MAILS MAY BE MONITORED BY THE COMPANY.
============================================================
--~------------------------------------------------------------------
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>
--~--