XSLT for each loop on simple XML

select the attributes by using the @ to distinghish attributes from elements. Tested on xslfiddle.net

xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="iso-8859-1" indent="no"/>

<xsl:template match="/">
    <xsl:for-each select="filters/ISP_WebItem">
      <xsl:value-of  select="@FILTER" />
      <xsl:value-of  select="@FILTERNAME" />
      <xsl:value-of  select="@UNITCODE" />
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>  

xml

<filters extra="filters">
    <ISP_WebItem FILTER="Farve" FILTERNAME="Sort" UNITCODE=""/>
    <ISP_WebItem FILTER="Længde" FILTERNAME="51" UNITCODE="cm"/>
    <ISP_WebItem FILTER="Højde" FILTERNAME="3.2" UNITCODE="cm"/>
    <ISP_WebItem FILTER="Dybde" FILTERNAME="9" UNITCODE="cm"/>
    <ISP_WebItem FILTER="Stavlængde" FILTERNAME="11" UNITCODE="cm"/>
</filters>

result

<html><head></head><body>FarveSortLængde51cmHøjde3.2cmDybde9cmStavlængde11cm</body></html>

Leave a Comment

error code: 523