Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-14-2009, 05:29 PM   PM User | #1
ngquochung86
New to the CF scene

 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ngquochung86 is an unknown quantity at this point
write the relative location for 2 elements with same name

My question is related to setting the XPath location for 2 XML elements with the same name, but both of them are not siblings of each other, for example some are ancestor of the other

Example like this: 1) Quotes/quote/play/title
2)Quotes/quote/play/sequence/scene/tittle

If I refer to title like "//title" in <xsl:value-of select = "//title", machine will not figure out which title I am mentioning, 1) or 2)

So is there other way to write the relative xpath location to refer to the TITLE like in the two absolute location above?

I don't wanna write long absolute location
Would you please help me? Thank you
ngquochung86 is offline   Reply With Quote
Old 04-14-2009, 06:02 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by ngquochung86 View Post
My question is related to setting the XPath location for 2 XML elements with the same name, but both of them are not siblings of each other, for example some are ancestor of the other

Example like this: 1) Quotes/quote/play/title
2)Quotes/quote/play/sequence/scene/tittle

If I refer to title like "//title" in <xsl:value-of select = "//title", machine will not figure out which title I am mentioning, 1) or 2)

So is there other way to write the relative xpath location to refer to the TITLE like in the two absolute location above?

I don't wanna write long absolute location
Would you please help me? Thank you
please post some xml and xslt to show what your problem is, only what is relevant. It's clear for me what do you ask but are many solution and each one depend on what you want to do.

best regards
oesxyl is offline   Reply With Quote
Old 04-15-2009, 01:50 AM   PM User | #3
ngquochung86
New to the CF scene

 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ngquochung86 is an unknown quantity at this point
My XML code:
Code:
<quotes>
  <quote>
    <!--play 1-->
    <play title="All's Well That Ends Well new">

      <act>
        <acttitle>ACT IV</acttitle>
        <scene title="SCENE I">
 
          <speech>
            <speaker>
              <name>LAFEU This is lafeu</name>
            </speaker>
            <line>He hath abandoned his physicians, madam; under whose
            practises he hath persecuted time with hope, and
            finds no other advantage in the process but only the
            losing of hope by time helllo world hello world hahah</line>
          </speech>
        </scene>
      </act>
    </play>
  </quote>
In the code above, I try to write the location path to locate the @ title of the scene and the play
Code:
	<xsl:value-of select="quote::descendent::act::child::@title"/>
              <xsl:value-of select="quote::child::@title"/>
I don't know why the 2 location path does not work. Would you please help me ?
ngquochung86 is offline   Reply With Quote
Old 04-15-2009, 04:38 AM   PM User | #4
ngquochung86
New to the CF scene

 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ngquochung86 is an unknown quantity at this point
I've just figured out how to do this, so there's no need to reply for this post. This post is now closed.
ngquochung86 is offline   Reply With Quote
Old 04-15-2009, 07:40 AM   PM User | #5
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by ngquochung86 View Post
I've just figured out how to do this, so there's no need to reply for this post. This post is now closed.
you could post your solution maybe somebody will have same problem.

Quote:
Originally Posted by ngquochung86 View Post
My XML code:
Code:
<quotes>
  <quote>
    <!--play 1-->
    <play title="All's Well That Ends Well new">

      <act>
        <acttitle>ACT IV</acttitle>
        <scene title="SCENE I">
 
          <speech>
            <speaker>
              <name>LAFEU This is lafeu</name>
            </speaker>
            <line>He hath abandoned his physicians, madam; under whose
            practises he hath persecuted time with hope, and
            finds no other advantage in the process but only the
            losing of hope by time helllo world hello world hahah</line>
          </speech>
        </scene>
      </act>
    </play>
  </quote>
In the code above, I try to write the location path to locate the @ title of the scene and the play
Code:
	<xsl:value-of select="quote::descendent::act::child::@title"/>
              <xsl:value-of select="quote::child::@title"/>
I don't know why the 2 location path does not work. Would you please help me ?
the way you write the path is incorrect but I guess you already discover this..
the path is relative to the template where you use. For example if you have a template for /quotes/quote/play will look like this:
Code:
<xsl:template match="play">
    <!-- second title -->
   <xsl:value-of select="act/scene/@title"/>
    <!-- first title -->
   <xsl:value-of select="@title"/>
</xsl:template>
on the other hand if you have distinct templates for play and @title:
Code:
<xsl:template match="play">
   <xsl:apply-templates select="act/scene/@title"/>
   <xsl:apply-templates select="@title"/>
</xsl:template>

<xsl:template match="@title">
   <xsl:value-of select="."/>
</xsl:template>
there are also few other combination.

best regards
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Tags
xml, xpath, xslt

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:42 PM.


Advertisement
Log in to turn off these ads.