0

I'm using XSLT to process an XML file and I'm having an error while looping through elements.

This is a snapshot of my XML file


<pl__pl_nc_name>
      <pl_nc_name_literal type="text_oneline">Value1</pl_nc_name_literal>
</pl__pl_nc_name>

...

<pl__pl_nc_name>
      <pl_nc_name_literal type="text_oneline">Value2</pl_nc_name_literal>
</pl__pl_nc_name>

To loop over <pl__pl_nc_name> I used for-each


 <plIdentifier_name_literal>
        <xsl:for-each select="pr:_nested__pl__pl_nc_name/pr:pl__pl_nc_name">
            <xsl:value-of select="pr:pl_nc_name_literal"/>
        </xsl:for-each>
 </plIdentifier_name_literal>

However, as output I'm having one element with the two values

<plIdentifier_name_literal>Value1Value2</plIdentifier_name_literal>

Instead I would like to have

<plIdentifier_name_literal>Value1</plIdentifier_name_literal>
<plIdentifier_name_literal>Value2</plIdentifier_name_literal>

I tried to add the @ before the pl_nc_name_literal like @pl_nc_name_literal but it doesn't work.

1 Answer 1

1

If you want to have an element for each node, you must create the element within the xsl:for-each instruction:

<xsl:for-each select="pr:_nested__pl__pl_nc_name/pr:pl__pl_nc_name">
    <plIdentifier_name_literal>
        <xsl:value-of select="pr:pl_nc_name_literal"/>
    </plIdentifier_name_literal>
</xsl:for-each>

P.S. xsl:for-each is not a "loop".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.