How to merge two xml and xsl into one?



How to combine two xml and two xsl into one xsl?


Each XML have own XSL, but I want to call those xsl into one xsl.


The output that I need, its like, there's a question and there are three options


Option 1: Form1 Option 2: Form2 Option 3: Others


If the client choose option 1, the xml and xsl of form1 will be call and display. Or if the client choose option 2, the xml and xsl for form2 will be call and display.


XML for Form 1



<Form xmlns:xsi="https://sitename"
name="CashPickup"
type="TextView"
label="Cash Pick-up Form">

<Field type="Delimiter"/>
<Field name="ContractNumber" type="TextView" label="Contract number" value=""/>

<Field type="Delimiter"/>
<Field name="ClientName" type="TextView" label="Name of Client" value=""/>
<Field name="BirthDate" type="TextView" label="Birthday" value=""/>
<Field name="DueDate" type="TextView" label="Due Date" value=""/>


XSL:



<xsl:template match="/">
<xsl:apply-templates select="Form"/>
</xsl:template>

<xsl:template match="Form">
<xsl:element name="Form">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="@label"/>
</xsl:attribute>
<xsl:copy-of select="namespace::*[not(name()='ns2') and not(name()='')]"/>
<xsl:call-template name="Arrange"/>
</xsl:element>
</xsl:template>

<xsl:template name="Arrange">

<xsl:apply-templates select="Field[@name='ContractNumber']"/>
<Field type="Delimiter"/>

<xsl:apply-templates select="Field[@name='ClientName']"/>
<xsl:apply-templates select="Field[@name='BirthDate']"/>
<xsl:apply-templates select="Field[@name='DueDate']"/>


XML Form 2:



<Form xmlns:xsi="https://sitename"
name="HomeVisitForm"
type="TextView"
label="Home Visit Form">
<Field type="Delimiter"/>
<Field name="ContractNumber" type="TextView" label="Application number" value=""/>
<Field name="TypeCheck" type="TextView" label="Type of check" value=""/>
<Field type="Delimiter"/>
<Field name="FirstName" type="TextView" label="First name" value=""/>
<Field name="SecondName" type="TextView" label="Second name" value=""/>


XSL:



<xsl:template match="/">
<xsl:apply-templates select="Form"/>
</xsl:template>

<xsl:template match="Form">
<xsl:element name="Form">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="@label"/>
</xsl:attribute>
<xsl:copy-of select="namespace::*[not(name()='ns2') and not(name()='')]"/>
<xsl:call-template name="Arrange"/>
</xsl:element>
</xsl:template>

<xsl:template name="Arrange">

<xsl:apply-templates select="Field[@name='ContractNumber']"/>
<xsl:apply-templates select="Field[@name='TypeCheck']"/>
<xsl:apply-templates select="Field[@name='VisitorName']"/>
<Field type="Delimiter"/>

<xsl:apply-templates select="Field[@name='FirstName']"/>
<xsl:apply-templates select="Field[@name='SecondName']"/>

No comments:

Post a Comment