Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ?

  • #4
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've just figured out how to do this, so there's no need to reply for this post. This post is now closed.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •