cancel
Showing results for 
Search instead for 
Did you mean: 

xslt problem

Former Member
0 Kudos

Hi all,

I'm sorry if my question is a bit off the topic / subject. I want to ask something about XI excel xslt transformation.

For ex. I have 2 worksheets, Header and Lineitems. Header details appear on one row only. The problem lies within the Lineitems. I can have multiple lineitems. I tried testing it in XI. I duplicated the ITEMS source node. But In the output,only one row is being created. I tried using the 'for-each' function but it did not work. I also tried apply-templates, did not work also. The code is somewhat like this:

<Row>

<xsl:for-each select="xxx/yyy/ITEM"/>

<Cell>

<Data ss:Type="String">

<xsl:value-of select="xxx/yyy/ITEM/VAR"/>

</Data>

</Cell>

</Row>

For every instance of ITEM node, I need to output a new Row. How can I do this in XSLT?

Any help would be greatly appreciated.

Thanks!

IX

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi IX,

Couple small things. First, your for-each is an empty node. You need to remove the trailing slash and close the for-each node when your looping is finished. Second, the path to VAR should be relative since you are inside a loop.


    <xsl:for-each select="/xxx/yyy/ITEM">
      <Row>
        <Cell>
          <Data ss:Type="String">
            <xsl:value-of select="./VAR"/>
          </Data>
        </Cell>
      </Row>
    </xsl:for-each>

Thanks,

-Russ

Former Member
0 Kudos

thanks.

your code worked russel. i have a problem though if the xpath is not the same as the VAR.

ex.

<xsl:for-each select="/xxx/yyy/ITEM">

<Row>

<Cell>

<Data ss:Type="String">

<xsl:value-of select="xxx/yyy/HEADER/VAR"/>

</Data>

</Cell>

</xsl:for-each>

output is not being shown when i use <xsl:value-of select="xxx/yyy/HEADER/VAR"/> or <xsl:value-of select="./VAR"/>. How can I use a variable from the HEADER node.

Former Member
0 Kudos

You need the root slash in your path to the HEADER nodes. Otherwise, it's looking here /xxx/yyy/ITEM/xxx/yyy/HEADER/VAR


    <xsl:for-each select="/xxx/yyy/ITEM">
      <Row>
        <Cell>
          <Data ss:Type="String">
            <xsl:value-of select="/xxx/yyy/HEADER/VAR"/>
          </Data>
        </Cell>
        <Cell>
          <Data ss:Type="String">
            <xsl:value-of select="./VAR"/>
          </Data>
        </Cell>
      </Row>
    </xsl:for-each>

Former Member
0 Kudos

Hi,

You can also use this:

Declare a variable before <xsl:for-each> like:

<xsl:variable name="Handler">

<xsl:value-of select="xxx/yyy/HEADER/VAR"/>

</xsl:variable>

and then use that variable inside ur <Data>:

<Data ss:Type="String">

<xsl:value-of select="string($Handler)"/>

</Data>

Thanks

Amit

Former Member
0 Kudos

i have one last question russell, what if i'm using a condition?

EX.

<xsl:for-each select="/ns0:SAPSRMRFQAward_CSV_MT/Recordset/ITEM">

<Row>

<Cell>

<Data ss:Type="String">

<xsl:choose>

<xsl:when test="xxx/yyy/ITEM/PLANT='000'">

<xsl:if test="/xxx/yyy/HEADER/PURCH_ORG='1000'">

<Data ss:Type="String">"'1000'"</Data>

</xsl:if test>

</xsl:when>

<xsl:otherwise>

<Data ss:Type="String">

<xsl:value-of select="./PLANT"/>

</Data>

</xsl:otherwise>

</xsl:choose>

</Cell>

</Row>

</xsl:for-each>

im getting the correct output for the otherwise block. i'm getting a blank for the if block. is there something wrong again with my xpath?

no need.. thanks!!!!

Edited by: Ignatius - Xavier Bazar on Feb 10, 2010 4:57 PM

Answers (2)

Answers (2)

former_member200962
Active Contributor
0 Kudos

The for-each does not seem to have been used properly....take help from this online example:

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=tryxsl_for-each

Regards,

Abhishek.

former_member204873
Contributor
0 Kudos

hi,

try to use,

<xsl:for-each select="xxx/yyy/ITEM"/>

<Row>

<Cell>

<Data ss:Type="String">

<xsl:value-of select="xxx/yyy/ITEM/VAR"/>

</Data>

</Cell>

</Row>

Thanks.