2
<?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..

Sambasiva
  • 1,034
  • 3
  • 14
  • 29
  • Could this be the issue - `href="@"..OfferLetter.xslt"`? It doesn't look like a valid value for the href attribute. – Tim Nov 29 '13 at 10:55
  • Could you be more specific in the "Does not get data" part? Does it output anything, Where are you running the XSLT (browser/tool/code)? – Marvin Smit Nov 29 '13 at 10:56
  • browser,and href="@..OfferLetter.xslt" not a problem and i am getting Dear Mr.,and after tag is not getting.. – Sambasiva Nov 29 '13 at 10:58
  • 1
    href="@..OfferLetter.xlst" might not be a problem, but your posted code has href="@"..OfferLetter.xlst" (note the quotation after the @). Typo in your post or in your file? – Tim Nov 29 '13 at 11:01
  • i changed my code..after u told that line..but tag is not getting data.. – Sambasiva Nov 29 '13 at 11:05

1 Answers1

1

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>
StuartLC
  • 96,413
  • 17
  • 181
  • 256
  • thanks for your answer..and i modified my extraneous @ in the xml as picked up by Tim ..but i am not getting and data from your code... – Sambasiva Nov 29 '13 at 11:14
  • @Samba, you have to tell us very clearly what you mean by "not getting any data". E.g. the error message you get, the wrong output you get... There is no way around that. Otherwise, you are wasting the time of SO users. – Mathias Müller Nov 29 '13 at 11:17
  • Copy both the `.xml` and `.xslt` file to the same folder, and then open the xml file in IE, or publish the files to the site and navigate your browser to the xml file, if that is how intend are serving the files. – StuartLC Nov 29 '13 at 11:21
  • ? After parsing the `xml` file through the `xsl` transform, `html` will be generated. – StuartLC Nov 29 '13 at 11:24
  • Which browser do you use? Look at the source code (in Firefox that's `Ctrl+U` for instance). Does the resulting HTML file look allright? – Mathias Müller Nov 29 '13 at 11:26
  • Note that Chrome won't by default allow a `file://` to transform from another `file://` - you'll need the [--allow-file-access-from-files](http://stackoverflow.com/questions/3828898/can-chrome-be-made-to-perform-an-xsl-transform-on-a-local-file) switch. – StuartLC Nov 29 '13 at 11:44
  • Error loading stylesheet: Parsing an XSLT stylesheet failed. in FIrefox – Sambasiva Nov 29 '13 at 11:51
  • 2
    Can't repeat, just downloaded and installed FF 25, out of the box. And works in IE 8 and 10, and Chrome 31.0 if launched via the --allow-file-access-from-files. Copy the first file into `OfferLetter.xml` and the second file to `OfferLetter.xslt` in the same directory. – StuartLC Nov 29 '13 at 12:00
  • @Mathias Müller firefox shows two lines of code ,that means where ever i entered html code shows only – Sambasiva Nov 29 '13 at 13:11