Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > select the following node

Reply
Thread Tools

select the following node

 
 
naima.mans@gmail.com
Guest
Posts: n/a
 
      01-17-2007
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="CommitmentNetAmounts" /> <!-- this one -->

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

</positionInfo>
</tradePart>

<tradePart product="L1712"> <!-- NOT this one -->
<positionInfo>
<positionRate>0.0000</positionRate> <!-- this one -->

<positionRate>20.0000</positionRate> <!-- this one -->
</positionInfo>
</tradePart>
</loanService>
-----------------------------------------------------

the XSLT:
--------------------------------------
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:diff="http://www.via.ecp.fr/~remi/soft/xml/xmldiff"
xmlns:msg="http://defiml.loanService.V3_40">
<xslutput 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="following-sibling::node()[position()=1]"></xsl:variable>

<xsl:if test="local-name($actual) = name($follow)">
<xsl:text> actual </xsl:text> <xsl:value-of
select="local-name($actual)"/>
<xsl:text>/ </xsl:text>
<xsl:text> follow </xsl:text><xsl:value-of select="name($follow)"
/>
<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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      01-17-2007
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 overcomplicating 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select nodes with child node A and child node B gplott@yahoo.com XML 1 11-01-2006 09:27 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
Select Node Using position or value of another node. Eddy C XML 6 10-17-2005 11:02 PM
XSL HOWDOI use attribute of current node to select a different node? CB XML 1 10-02-2003 02:37 PM



Advertisments