Reputation: 27
I am facing an issue where I have to replace string dynamically in loop. I have to convert an XML into HTML.
XML Structure is:
<FUNCTION ID="XYZ" UNIT_TYPE="percent"/>
<STRING_LITERAL><![CDATA[1143]]></STRING_LITERAL>
<STRING_LITERAL><![CDATA[1]]></STRING_LITERAL>
<STRING_LITERAL>NULL</STRING_LITERAL>
<STRING_LITERAL>NULL</STRING_LITERAL>
<STRING_LITERAL><![CDATA[Prepaid]]></STRING_LITERAL>
<STRING_LITERAL>NULL</STRING_LITERAL>
<BOOLEAN>true</BOOLEAN>
<BOOLEAN>true</BOOLEAN>
<STRING_LITERAL>NULL</STRING_LITERAL>
<STRING_LITERAL>NULL</STRING_LITERAL>
<STRING_LITERAL>NULL</STRING_LITERAL>
<STRING_LITERAL>NULL</STRING_LITERAL>
</FUNCTION>
The HTML output expected is:
Scheme : 1143
Payout : 1
Deposit: Prepaid
Target : true
Is Reprotable : true
I checked the solution at : xslt 1.0 string replace function but I am unable to apply it in this case. Please help.
Upvotes: 0
Views: 442
Reputation: 3248
I'm not quite clear about what you're trying to do. But a very simple XSLT 1.0 to generate your expected output from the input you posted could look like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>test</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="FUNCTION">
<p>
<xsl:text>Scheme : </xsl:text>
<xsl:value-of select="STRING_LITERAL[1]"/>
<br/>
<xsl:text>Payout : </xsl:text>
<xsl:value-of select="STRING_LITERAL[2]"/>
<br/>
<xsl:text>Deposit : </xsl:text>
<xsl:value-of select="STRING_LITERAL[5]"/>
</p>
<p>
<xsl:text>Target : </xsl:text>
<xsl:value-of select="BOOLEAN[1]"/>
<br/>
<xsl:text>Is Reprotable : </xsl:text>
<xsl:value-of select="BOOLEAN[2]"/>
</p>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1