0

How to add data into xslt array from outside the tag..

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
    xmlns:array="http://www.w3.org/2005/xpath-functions/array" exclude-result-prefixes="#all"
    version="3.0">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:param name="input"/>
    
    <xsl:variable name="newline" select="'&#10;'"/>
    <xsl:template match="/" name="xsl:initial-template">
        <xsl:variable name="input-as-map" select="parse-json($input)" as="map(*)"/>
        <root>
            
            <!-- storing all the PERSONNUMBER present in the ibop -->
            <xsl:variable name="item-array" as="element()*">
                    <Item>A</Item>
                    <Item>A</Item>
                    <Item>A</Item>
                    <Item>b</Item>              
            </xsl:variable>   
        </root>
    </xsl:template>    
</xsl:stylesheet>

Here I'm adding the values inside an variable within the opening and closing <xsl:variable> ..

So how to add values into an item-array based on name attribute(outside an variable tags)..

like how we do in other programs..emphasized text

1
  • 3
    You have a variable with a sequence of element nodes, not an array of element nodes. In XSLT 3, you can add to an array but it will also give you a new array. But your example binds a sequence of elements, not an array. Commented Jun 12, 2021 at 9:18

2 Answers 2

2

To give you can example of redeclaring and rebinding a variable you can use e.g.

   <xsl:variable name="elements" as="element(item)*">
        <item>a</item>
        <item>b</item>
        <item>c</item>
    </xsl:variable>
    <xsl:variable name="elements" as="element(item)*">
        <xsl:sequence select="$elements"/>
        <item>d</item>
    </xsl:variable>
    <xsl:copy-of select="$elements"/>

and you will get

  <item>a</item>
  <item>b</item>
  <item>c</item>
  <item>d</item>
Sign up to request clarification or add additional context in comments.

Comments

1

So how to add values into an item-array based on name attribute(outside an variable tags)..

You can't. All XSLT variables are immutable.

If you want to have a variable with a different value, create a new one.

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.