Hi,
As a follow on from an earlier post I have another question about
xslt.
Is it possible to create the stylsheet programatically? Is this
sensible? In the first phase I needed to map element name from inbound
xml to my internal elements to standardize disparate input.
Now I could just create an xslt stylesheet for each possible inbound
format and be done, but I think it would be powerful to be able store
this mapping in a database and programatically create the stylsheet.
This way I don't have to maintain potentially a great number of
stylesheets. The trouble is, I can't find any example where the
stylesheet is not Load'ed from a file.
Can someone provide an example of creating the stylesheet
programatically to pass to an XslTransform.Load method?
Do I just write out the XML to a string?
Maybe my example from before would help...
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="NewDataSet" >
<MyDataSet>
<xsl:apply-templates select="Cust" />
</MyDataSet>
</xsl:template>
<xsl:template match="Cust">
<MyCustomer>
<xsl:apply-templates select="nameFirst" />
<xsl:apply-templates select="nameLast" />
<xsl:apply-templates select="addrCity" />
<xsl:apply-templates select="addrState" />
<xsl:apply-templates select="addrStreet" />
<xsl:apply-templates select="addrZIP" />
</MyCustomer>
</xsl:template>
<xsl:template match="nameFirst">
<MyFname>
<xsl:value-of select="text()" />
</MyFname>
</xsl:template>
<xsl:template match="nameLast">
<MyLname>
<xsl:value-of select="text()" />
</MyLname>
</xsl:template>
<xsl:template match="addrCity">
<MyCity>
<xsl:value-of select="text()" />
</MyCity>
</xsl:template>
<xsl:template match="addrState">
<MyState>
<xsl:value-of select="text()" />
</MyState>
</xsl:template>
<xsl:template match="addrStreet">
<MyStreet>
<xsl:value-of select="text()" />
</MyStreet>
</xsl:template>
<xsl:template match="addrZIP">
<MyZIPPO>
<xsl:value-of select="text()" />
</MyZIPPO>
</xsl:template>
</xsl:stylesheet>
Thanks in advance,
Pint