Jump to content

Looping in XSLT


bothwell

Recommended Posts

N00b to XSLT - can't quite figure out how this loop works.

 

The code below returns the first result from <photos> rather than all three from the node.

 

How can I return all of the results in a loop?

 

XML:

<properties>
  <property>
    <propertyID>135427</propertyID>
    <photos>
      <photo>/proppics/594/picture_130428_1.gif</photo>
      <photo>/proppics/594/picture_130428_2.gif</photo>
      <photo>/proppics/594/picture_130428_3.gif</photo>
    </photos>
  </property>
</properties>

 

XSLT:

<xsl:template match="/">
	<xsl:for-each select="properties/property[propertyID=$id]">
		<tr>
			<th><xsl:value-of select="ShortAddress1"/>, <xsl:value-of select="Area"/>, <xsl:value-of select="City"/>, <xsl:value-of select="Postcode"/></th>
		</tr>
		<tr> 
			<td>	
				<xsl:element name="allpics">
				    <xsl:call-template name="pics"></xsl:call-template>
				</xsl:element>
			</td> 
		</tr> 
	</xsl:for-each> 
</xsl:template>

<xsl:template match="photos" name="pics">
        <xsl:for-each select="photos">
     	  <p><xsl:value-of select="photo"/></p>
        </xsl:for-each>
</xsl:template>

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/177243-looping-in-xslt/
Share on other sites

Resolved. The answer is to use a dot as the select value rather than the node title (while selecting the parent node of the one you want to loop ;) ).

 

<xsl:template match="photos" name="pics">
          <xsl:for-each select="photos/photo">
            <xsl:sort select="photo"/>
            <p>[i][b][u]<xsl:value-of select="."/>[/u][/b][/i]</p>
          </xsl:for-each>
</xsl:template>

Link to comment
https://forums.phpfreaks.com/topic/177243-looping-in-xslt/#findComment-934881
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.