select the following node

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • naima.mans@gmail.com

    #1

    select the following node

    Hello,

    i want to select 2 following brothers nodes wich are one under another
    (one closed to another)... i have done one xslt file... but it's not
    really good..

    for example:
    the xml file:
    -----------------------------------------------------
    <loanService>
    <tradePart product="L1712" <!-- NOT this one -->
    <positionInfo >
    <position partyReference= "EXPCFTCL"
    code="Commitmen tNetAmounts" /<!-- this one -->

    <position partyReference= "EXPCFTCL"
    code="Commitmen tNetAmount" / <!-- this one -->

    </positionInfo>
    </tradePart>

    <tradePart product="L1712" <!-- NOT this one -->
    <positionInfo >
    <positionRate>0 .0000</positionRate <!-- this one -->

    <positionRate>2 0.0000</positionRate <!-- this one -->
    </positionInfo>
    </tradePart>
    </loanService>
    -----------------------------------------------------

    the XSLT:
    --------------------------------------
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:diff="htt p://www.via.ecp.fr/~remi/soft/xml/xmldiff"
    xmlns:msg="http ://defiml.loanServ ice.V3_40">
    <xsl:output method="text" encoding="ISO-8859-1" />

    <xsl:strip-space elements="*" />
    <xsl:template match="/">
    <xsl:apply-templates select="//*"/>
    </xsl:template>

    <xsl:template match="//*">

    <xsl:variable name="actual" select="."></xsl:variable>
    <xsl:variable name="follow"
    select="followi ng-sibling::node()[position()=1]"></xsl:variable>

    <xsl:if test="local-name($actual) = name($follow)">
    <xsl:textactu al </xsl:text<xsl:va lue-of
    select="local-name($actual)"/>
    <xsl:text>/ </xsl:text>
    <xsl:textfoll ow </xsl:text><xsl:v alue-of select="name($f ollow)"
    />
    <xsl:text; </xsl:text>
    <xsl:text>
    </xsl:text>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    --------------------------------------

    the result:
    --------------------------------------
    actual tradePart/ follow tradePart
    ;
    actual position/ follow position ;
    actual positionRate/ follow positionRate ;
    --------------------------------------


    The problem is that I want this result:
    actual position/ follow position
    ;
    actual positionRate/ follow positionRate ;

    I just want to select the brother which are just one under another ...

    thanks a lot

    Tachi

  • Joe Kesselman

    #2
    Re: select the following node

    Since you haven't told us what you're really trying to accomplish
    ("brother" is not a defined term in XPath and XSLT.), it's hard to say
    whether you are overcomplicatin g the problem or not.

    If you really need the same-name-as-first-child-element test, then yes,
    it's going to be somewhat ugly. (And in fact you should probably be
    checking namespace as well as localname.) If you just need the first two
    child elements no matter what their names are, or if you know the names
    at the time you're writing the stylesheet, that's a significantly simpler.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

    Comment

    • naima.mans@gmail.com

      #3
      Re: select the following node

      On 17 jan, 14:20, Joe Kesselman <keshlam-nos...@comcast. netwrote:
      Since you haven't told us what you're really trying to accomplish
      ("brother" is not a defined term in XPath and XSLT.), it's hard to say
      whether you are overcomplicatin g the problem or not.
      >
      If you really need the same-name-as-first-child-element test, then yes,
      it's going to be somewhat ugly. (And in fact you should probably be
      checking namespace as well as localname.) If you just need the first two
      child elements no matter what their names are, or if you know the names
      at the time you're writing the stylesheet, that's a significantly simpler.
      >
      --
      () ASCII Ribbon Campaign | Joe Kesselman
      /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
      hello

      thanks for your answer.. by brother i mean the following node

      i have found what want with following-sibling::node()[position()=1]

      for information here my xslt:
      --------------------------------------------------

      <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
      Transform" xmlns:msg="http ://xxxxxxxxxx">
      <xsl:output method="text" encoding="ISO-8859-1" />
      <xsl:strip-space elements="*" />
      <xsl:template match="@*|node( )">
      <xsl:copy>
      <xsl:apply-templates select="@*|node ()" />
      </xsl:copy>
      </xsl:template>
      <xsl:template match="/">
      <!--<xsl:element name="changes"-->
      <xsl:apply-templates select="//*" />
      <!--</xsl:element-->
      </xsl:template>
      <xsl:template match="//*">
      <xsl:variable name="actual" select="."/>
      <xsl:variable name="follow" select="followi ng-sibling::node()
      [position()=1]"/>
      <xsl:variable name="brother" select="*[position()=1]"/>
      <xsl:if test="local-name($actual) = name($follow)">
      <xsl:if test="name($bro ther)=''">
      <xsl:value-of select="local-name($actual)"/><xsl:text~ </xsl:text>
      <!-- value before -->
      <xsl:value-of select="($actua l)"/><xsl:text~ </xsl:text>
      <!-- value after -->
      <xsl:value-of select="($follo w)"/><xsl:text~ </xsl:text>
      <!-- attribut before -->
      <xsl:for-each select="($actua l/@*)">
      <xsl:value-of select="local-name()"/>
      <xsl:text= </xsl:text>
      <xsl:value-of select="."/>
      <xsl:if test="position( )!=last()", </xsl:if>
      </xsl:for-each>
      <xsl:text~ </xsl:text>
      <!-- attribut after -->
      <xsl:for-each select="($follo w/@*)">
      <xsl:value-of select="local-name()"/>
      <xsl:text= </xsl:text>
      <xsl:value-of select="."/>
      <xsl:if test="position( )!=last()", </xsl:if>
      </xsl:for-each>
      <xsl:text~ </xsl:text>
      <xsl:for-each select="ancesto r::*">
      <xsl:value-of select="local-name()"/>
      <xsl:text( </xsl:text>
      <xsl:for-each select="@*">
      <xsl:value-of select="local-name()"/>
      <xsl:text= </xsl:text>
      <xsl:value-of select="."/>
      <xsl:if test="position( )!=last()", </xsl:if>
      </xsl:for-each>
      <xsl:text) </xsl:text>
      <xsl:if test="position( )!=last()"/ </xsl:if>
      </xsl:for-each>
      <xsl:text> </xsl:text>
      </xsl:if>
      </xsl:if>
      </xsl:template>
      </xsl:stylesheet>

      Comment

      Working...