I have a input XML which looks like below:
<A>
<B id="1"></B>
<C id="2">
<D id="3"></D>
</C>
<A>
I want output like below:
<!DOCTYPE HTML SYSTEM "about:legacy-compat"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Form1</title>
</head>
<body>
<DIV>
<div id="1"></div>
<Div id="2">
<div id="3">
</div>
</div>
</Div>
But I am getting like below:
<!DOCTYPE HTML SYSTEM "about:legacy-compat"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Form1</title>
</head>
<body>
<DIV>
<div id="1"></div>
<Div id="2">
<div id="3">
</div>
</div>
<Div id="2">
<div id="3">
</div>
</div>
</Div>
--------
My xslt looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="html" doctype-system="about:legacy-compat" encoding="UTF-8" indent="yes" />
<xsl:variable name="vbLookup" select="document('Vblookup.xml')/VbLookup"/>
<xsl:param name="list1" select="$vbLookup/*"/>
<xsl:param name="list2" select="xml/Form/*"/>
<xsl:param name="formName" select="xml/Form/@Name"/>
<xsl:template match="/">
<html>
<head>
<meta charset="UTF-8"/>
<title><xsl:value-of select="xml/Form/@Caption"/></title>
</head>
<body>
<xsl:call-template name="process-form"/>
</body>
</html>
</xsl:template>
<xsl:template name="process-form" match="Form">
<xsl:for-each select="$vbLookup/VBFormObject">
<xsl:if test="@Name=$formName">
<xsl:element name="{@Html5Object}">
<xsl:call-template name="process-children"/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="process-children">
<xsl:for-each select="$list2">
<xsl:call-template name="make-html-elements">
<xsl:with-param name="name" select="@Name"/>
<xsl:with-param name="id1" select="@Id"/>
<xsl:with-param name="childNodes" select="child::node()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="make-html-elements">
<xsl:param name="name" />
<xsl:param name="id1"/>
<xsl:param name="childNodes"/>
<xsl:for-each select="$list1">
<xsl:if test="@Name=$name and not(contains(@Html5Object,'input')) and not(contains(@Html5Object,'select'))">
<xsl:text disable-output-escaping="yes"><![CDATA[<]]></xsl:text>
<xsl:value-of select="@Html5Object"/>
<xsl:text> id="</xsl:text><xsl:value-of select="$id1"/>
<xsl:text>"</xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
<xsl:for-each select="$childNodes">
<xsl:variable name="fname" select="@Name"/>
<xsl:variable name="id" select="@Id"/>
<xsl:variable name="fchildNode" select="child::node()"/>
<xsl:call-template name="make-html-elements">
<xsl:with-param name="name" select="$fname"/>
<xsl:with-param name="childNodes" select="$fchildNode"/>
</xsl:call-template>
</xsl:for-each>
<xsl:text disable-output-escaping="yes"><![CDATA[</]]></xsl:text>
<xsl:value-of select="@Html5Object"/><xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I am not sure where the for each is executing twice for generating the child nodes twice which is incorrect. Ant help will be appreciated. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire