tags:

views:

62

answers:

3

Hey everyone im trying to use

<xsl:for-each select="//node1">

in my xsl the problem is that it gets all the nodes name node1 together and not passing them one by one (as for each should be) just for you to know im using // pattern becuase my xml changes and i do need to find inside some node the node1

hope you can help...

+1  A: 

Try this instead:

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

It is hard to say why you are seeing the issue that you are seeing as a for-each should work just fine but it is often better to use the declarative approach to coding in XSLT (as I have shown above) as opposed to the more procedural for-each.

Edit: Okay - I think I see what is going on now.

Try this:

<another-att>
    <xsl:for-each select="paragraph/text">
     <xsl:if test="position() != 0">,</xsl:if>
     <xsl:value-of select="@textvalue"/>
    </xsl:for-each>
</another-att>
Andrew Hare
added the question as answer....
well in this example i guess it would work but in my real xml it won't becuase i have more children until you get to paragraph/text ...and im working with alot of xml files and the wat into paragraph/text may be diffrent...
i thought about doing something likefor-each on the another-attand then use for-each with //textbut it gives me the same result....
ok found the answer....just added "." before the "//text" and it worksthanks anyway
A: 

first of all sorry im adding it as an answer it just a bit long (more than 600 chars ) ....

ok so my xml looks like this

<father>
   <object>
   <attribute att.type="type">
    <another-att>
     <paragraph>
     <text textvalue="first "/>
     </paragraph>
      <paragraph>
     <text textvalue="second"/>
     </paragraph>
     <paragraph>
     <text textvalue="third "/>
     </paragraph>
    </another-att>
   </attribute>
  </object>

<model>
<attribute att.type="type">
    <another-att>
     <paragraph>
     <text textvalue="fourth "/>
     </paragraph>
      <paragraph>
     <text textvalue="fifth"/>
     </paragraph>
     <paragraph>
     <text textvalue="sixth"/>
     </paragraph>
    </another-att>
   </attribute>

</model>


</father>

and my xsl looks like this

 <xsl:template match="//attribute[@att.type='type']/another-att">

                    <another-att>
                        <xsl:for-each select="//text">
                            <xsl:if test="position() != 0">,</xsl:if>
                            <xsl:value-of select="@textvalue"/>
                        </xsl:for-each>
                    </another-att>



    </xsl:template>

and the problem is im getting

2 nodes of with the values of first , second , third , fourth , fifth , sixth

Stackoverflow is not a forum. Long length is not a valid reason to put part of your question in an answer. Edit the question instead.
Wim Coenen
A: 

found the answer edited "//text" into ".//text"

thanks everyone