1.11M Members

XSLT - for-each nestled problem

 
0
 

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

 
0
 

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 :)

 
1
 

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>

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article