Question

I am trying to pass an xml path as string to the template.

<xsl:call-template name="checkPath">
    <xsl:with-param name="path" select="'parent/child1'" />
</xsl:call-template>

Inside the template, i am appending a child to the passed string to check for the existence of a child element with the path and a given name.

<xsl:template name="checkPath">
    <xsl:param name="path"/>
    <xsl:variable name="childElement" select="child-name"/>
    <xsl:if test="$path/child2[name=$childElement]">
         //Do some processing.  
    </xsl:if>
</xsl:template>

The above XSL gives me the following error.

Invalid conversion from 'java.lang.String' to 'node-set'.

I am trying to parse the below XML.

<parent>
    <child1>
        <child2>
            <name>name1</name>
        </child2>
    </child1>
</parent>

.....
<child-name>name1</child-name>
Was it helpful?

Solution

Don't pass the path as a string, just remove the quotes and pass the actual node set that the path selects.

<xsl:call-template name="checkPath">
    <xsl:with-param name="path" select="parent/child1" />
</xsl:call-template>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top