Reputation: 1044
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="@..OfferLetter.xslt"?>
<Doc>
<assembly>
<Heading>Offer Letter</Heading>
</assembly>
<RefNo>Ref No:0007</RefNo>
<Date></Date>
<to>To</to>
<name></name>
<city></city>
<dear>
<a>Dear Mr.</a>
<name></name>
</dear>
<p1>
<a1>
With reference to your application and the subsequent personal interview attended by you,
we are pleased to inform that you have been selected for employment in ..
(hereinafter referred to as “Company”).
We are delighted to make you the following offer for employment.
</a1>
</p1>
</Doc>
here my xslt code for that..
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="/">
<html>
<body>
<h2 style ="text-align: center;">Offer Letter</h2>
<h3 style="text-align:Right; margin-right: 110px;">Ref No:K070813</h3>
<h3 style="text-align:Right ; margin-right: 224px; ">Date:</h3>
<h3 style="text-align:Left; margin-left: 50px;">To</h3>
<h3 style="text-align:Left; margin-left: 50px;">MR.</h3>
<h3 style="text-align:Left; margin-left: 50px;">Hyderabad</h3>
<br></br>
<h3 style="text-align:Left; margin-left: 50px;">Dear Mr.</h3>
<xsl:for-each select="Doc/p1">
<h3 style="text-align:Left; margin-left: 50px;">
<xsl:value-of select="a1"/>
</h3>
</xsl:for-each>
</body>
</html>
here my TransformHRML() code
public static void TransformXML()
{
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
// transform the OfferLetter.xml file to HTML
XslTransform transform = new XslTransform();
// load up the stylesheetfile:
transform.Load(HttpContext.Current.Server.MapPath("OfferLetter.xslt"));
// perform the transformation
transform.Transform(@"..\OfferLetter.xml", @"..\OfferLetter.html", resolver);
// transform the OfferLetter.xml file to comma delimited format
// load up the stylesheet
transform.Transform(HttpContext.Current.Server.MapPath("OfferLetter.xslt"), @"..\OfferLetter.html",resolver);
}
please help me..
Upvotes: 2
Views: 318
Reputation: 107387
There are a bunch of close-tag issues, and the extraneous @
in the xml
file as picked up by Tim.
After tidying these up, your xslt
works, but I would push you to use apply-templates
and not for-each
:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="OfferLetter.xslt"?>
<Doc>
<assembly>
<Heading>Offer Letter</Heading>
</assembly>
<RefNo>Ref No:0007</RefNo>
<!--etc-->
<p1>
<a1>
With reference to your application and the subsequent , ...
</a1>
</p1>
<p1>
<a1>
Another Paragraph
</a1>
</p1>
</Doc>
With the XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="/">
<html>
<body>
<!--Did you mean to hard code these fields? -->
<h2 style ="text-align: center;">
<xsl:value-of select="assembly/Heading"/>
</h2>
<h3 style="text-align:Right; margin-right: 110px;">
<xsl:value-of select="assembly/RefNo"/>
</h3>
<!--etc-->
<xsl:apply-templates select="Doc/p1">
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="p1">
<h3 style="text-align:Left; margin-left: 50px;">
<xsl:value-of select="a1"/>
</h3>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1