...

View Full Version : write the relative location for 2 elements with same name



ngquochung86
04-14-2009, 06:29 PM
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

oesxyl
04-14-2009, 07:02 PM
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

ngquochung86
04-15-2009, 02:50 AM
My XML 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

<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
04-15-2009, 05:38 AM
I've just figured out how to do this, so there's no need to reply for this post. This post is now closed.

oesxyl
04-15-2009, 08:40 AM
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.


My XML 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

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


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


<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum