xsl-list
[Top] [All Lists]

[xsl] Retrieving Complete XPATH from XML File

2010-11-09 00:50:00
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>