Hi,
I have a problem with a nestled "for-each". I want information from every orditem. Every orderitem have one "orderitem id" and could have several "job id". The sample belove do not work,any suggestions?

XML

<order orderid="20">
  <workflows>
    <workflow id="97"
      <items>
        <orderitem id="1">
          <jobs>
            <job id="150"/>
            <job id="151"/>
          </jobs>
        </orderitem>
      </items>
    </workflow>
    <workflow id="97">
      <items>
        <orderitem id="2">
          <jobs>
            <job id="152"/>
          </jobs>
        </orderitem>
      </items>
    </workflow>
  </workflows>
</order>

XSLT

    <xsl:for-each select="//items/orderitem[@id != '0']">
          <xsl:value-of select="@item-number"/>
      <xsl:for-each select="/order/jobs/job">
            <xsl:value-of select="@id"/>
          </xsl:for-each>
    </xsl:for-each>

I want the output to be:
1 150 151
2 152

Kind regards / trady

Hi Trady,

I got the result layout you wanted using the following XSLT stylesheet:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:cs="urn:cs"
  exclude-result-prefixes="cs msxsl" >

  <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>

  <xsl:template match="order">
    <xsl:apply-templates select="workflows"/>
  </xsl:template>

  <xsl:template match="workflows">
    <xsl:for-each select="workflow/items/orderitem">
      <xsl:value-of select="@id"/>
      <xsl:text>&#32;</xsl:text>
      <xsl:for-each select="jobs/job">
        <xsl:value-of select="@id"/>
        <xsl:text>&#32;</xsl:text>
      </xsl:for-each>
      <xsl:text>&#0010;</xsl:text>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Hope this helps :)

do not think as programmers
the loops are therefore not necessary
think in terms of how it was developed template xslt

Use only the nodes where the information is contained

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
<xsl:template match="/">
<xsl:apply-templates select="child::*//jobs"/>
</xsl:template>
<xsl:template match="jobs">
<xsl:value-of select="position()"/>
<xsl:apply-templates select="job"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>
<xsl:template match="job">
<xsl:value-of select="concat(' ',@id)"/>
</xsl:template>
</xsl:stylesheet>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.