xsl-list
[Top] [All Lists]

Re: [xsl] Retrieving Complete XPATH from XML File

2010-11-09 02:52:20
whitout values, I think it's something like that

my xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
 <xsl:template match="/">
  <parcours>
   <xsl:apply-templates select="//*" mode="parcours"/>
  </parcours>
 </xsl:template>
 <xsl:template match="*" mode="parcours">
  <xpath>
   <xsl:apply-templates select="." mode="ecriture"/>
  </xpath>
 </xsl:template>
 <xsl:template match="*" mode="ecriture">
  <xsl:apply-templates select="parent::*" mode="ecriture"/>/<xsl:value-of 
select="name()"/>
  <xsl:apply-templates select="@*"/>
 </xsl:template>
 <xsl:template match="text()"/>
 <xsl:template match="@*">[@<xsl:value-of select="name()"/>]</xsl:template>
</xsl:stylesheet>

my result

<?xml version="1.0" encoding="UTF-8"?>
<parcours>
 <xpath>/quizzes</xpath>
 <xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/prompt</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id][@correct]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/option[(_at_)id]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id]</xpath>
 
<xpath>/quizzes/quiz[(_at_)id][@title][(_at_)maxQuestions]/question[(_at_)id][@type]/feedback[(_at_)id]</xpath>
</parcours>
----- Message d'origine ----- 
De : "Ramkumar.V" <ramkumar(_dot_)v(_at_)hurix(_dot_)com>
À : <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Envoyé : mardi 9 novembre 2010 07:44
Objet : [xsl] Retrieving Complete XPATH from XML File


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>
--~--