I've been trying to get a value from a XML and create this output:
OUTPUT1=Question1=No&Question2=Yes
My current output is:
Question1=No
Question2=Yes
I don't know the best approach to do this, I'm new to XSLT and I was thinking to store these values into a variable and use them later like: OUTPUT1=Variable1&Variable2
But even that it is a challenge to me, can someone help me with directions ?
XSLT
<xsl:template match="/">
<xsl:call-template name="processQuestion">
<xsl:with-param name="name" select="'ADM_1'"></xsl:with-param>
</xsl:call-template>
<xsl:call-template name="processQuestion">
<xsl:with-param name="name" select="'ADM_2'"></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="processQuestion">
<xsl:param name="name"></xsl:param>
<xsl:apply-templates select="//x:form/x:add[@name=$name]" mode="process" />
</xsl:template>
<xsl:template match="x:add" mode="process">
<xsl:value-of select="@title"/>=<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:template>
XML
<?xml version="1.0" encoding="iso-8859-1"?>
<transaction xmlns="TransactionDataOfRequest" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<success>true</success>
<code>0</code>
<value>
<form>
<add name="ADM_1" title="Question 1" type="String" isList="false">No</add>
<add name="ADM_2" title="Question 2" type="String" isList="false">Yes</add>
</form>
</value>
</transaction>
Variable
<xsl:variable name="test">
<xsl:value-of select="."/>
</xsl:variable>
I've also tried this:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="TransactionDataOfRequest">
<xsl:output method="text" indent="no"/>
<xsl:output omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:param name="param1" select="'ADM_1'"/>
<xsl:param name="param2" select="'ADM_2'"/>
<xsl:for-each select="//x:form/x:add">
<xsl:if test="@name=$param1">
Question1=<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="//x:form/x:add">
<xsl:if test="@name=$param2">
<xsl:variable name="test">
<xsl:value-of select="."/>
</xsl:variable>
Question2=<xsl:copy-of select="$test" />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
That was my first attempt, in fact I was able to save the value into a variable, but that variable only exist inside that template right?