<need help>How to print the preceding node value based on descendant node in XSLT?

Discussion in 'XML' started by njsimha, Sep 16, 2008.

  1. njsimha

    njsimha

    Joined:
    Sep 12, 2008
    Messages:
    3
    Hi,
    In the folowing XML snippet:

    Code:
    <template1>
    <name>student</name>
    <elem1>
    <[B]subelem1[/B]>65</[B]subelem1[/B]>
    <subelem2>15</subelem2>
    </elem1>
    <[B]elem2[/B]>100</[B]elem2[/B]>
    </template1>
    
    </root>
    
    For the above code,I need to display an error:
    "elem2 node is not allowed for name=student as subelem1 is greater than 50"

    so the requirement is,elem2 should not be present if subelem1 is > 50.

    I have the following XSLT code:

    <xsl:template match="/root/template1/elem1/subelem1">
    <xsl:variable name="value" select="." />
    <xsl:if test="$value > 50" >
    subelem1 is greater than 50
    <xsl:if test="../../elem2" >
    <xsl:message terminate="yes">
    <xsl:value-of select="concat("elem2 is not allowed for name=....")/>
    elem4 exists
    </xsl:if>
    </xsl:if>
    </xsl:template>

    Using the above code,I am able to print the error as "elem2 is not allowed for name= ".
    Here I am not able to print "name=student".How to print the value of name node?

    Also please note that there will be 10 <template1> nodes.so the XSLT has to work for each template1.

    Please reply me how to achieve this.

    Thanks,
     
    njsimha, Sep 16, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sven

    XSLT preceding problem

    Sven, Jul 7, 2003, in forum: XML
    Replies:
    2
    Views:
    6,760
  2. Tjerk Wolterink
    Replies:
    2
    Views:
    1,443
    Dimitre Novatchev
    Aug 24, 2006
  3. Matt Waite
    Replies:
    4
    Views:
    353
    Matt Waite
    Feb 1, 2007
  4. tamak
    Replies:
    4
    Views:
    1,498
    Peter Flynn
    Apr 7, 2008
  5. ziggs
    Replies:
    1
    Views:
    172
    Ken Schaefer
    Jul 2, 2003
Loading...

Share This Page