I want to use XML attribute's value and store and compare it in the XSL file. I am converting the XSL to an HTML through a JAVA program, which is working fine. The output HTML is:-
Value =
XML file:
<root>
<Request>
<Desc>Insert new team into the table</Desc>
<Param name="teamName" required="false"/>
<Param name="rankings" required="true"/>
<Update requires="teamName,rankings" >
INSERT INTO standing (teamName,rankings) VALUES($rankings,$rankings)
</Update>
</Request>
XSL file:
<xsl:template match="root">
<xsl:variable name="UpdateRequires"/>
<html>
<head>
<title>DocStyle.xsl</title>
</head>
<body>
<xsl:for-each select="*/Request">
<xsl:for-each select="*/Update">
<xsl:variable name="UpdateRequires" select="*/Update/@requires"/>
</xsl:for-each>
</xsl:for-each>
<h1>
Value = <xsl:value-of select="$UpdateRequires"/>
</h1>
</body>
</html>
</xsl:template>
I want to display the value of the variable "UpdateRequires", and then compare it with Param tag's attribute "@name" maybe like this "contains(@name,UpdateRequires)"
UPDATE 1.0:
I am able to fetch the value of the variable, now I want to compare the value of the variable $UpdateRequires and the value of the attribute @name. It should return true for contains(@name,$UpdateRequires) which it's not doing (the if loop with test="@name" was just to check the values)
Changes made to XSL:
<xsl:for-each select="Request">
<xsl:variable name="UpdateRequires" select="*/@requires"/>
<xsl:for-each select="Update">
<xsl:variable name="UpdateRequires" select="@requires"/>
<h1>
We are in Update : <xsl:value-of select="$UpdateRequires"/>
</h1>
</xsl:for-each>
<xsl:for-each select="Param">
<xsl:if test=" contains(@name,$UpdateRequires) ">
<span>
We are in Param : <xsl:value-of select="$UpdateRequires"/>
</span>
</xsl:if>
<xsl:if test=" @name ">
<span>
We are in Param : <br/> Value of variable : <xsl:value-of select="$UpdateRequires"/> Value of name : <xsl:value-of select="@name"/> <br/>
</span>
</xsl:if>
</xsl:for-each>
Request
? And can aRequest
have more than oneUpdate
? – michael.hor257kcontains()
function takes strings as arguments, you cannot feed it a node-set. – michael.hor257k