xslt没有从xml获取数据? [英] xslt is not getting data from xml?

查看:66
本文介绍了xslt没有从xml获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?  xml     version   =  1.0    编码  = < span class =code-keyword> utf-8  >  
<? xml-stylesheet type = text / xsl < span class =code-summarycomment> href = @ .. OfferLetter.xslt >
< 文档 >
< 汇编 >
< 标题 > 商品信函< /标题 >
< / assembly >
< < span class =code-leadattribute> RefNo > 参考编号:0007 < / RefNo >
< 日期 > < / Date >
< > < / to >
< 名称 > < ; / name >
< city > < / city >
&L t; 亲爱的 >
< a > 亲爱的先生< / a >
< 名称 > < / name >
< / dear >
< p1 >
< a1 >
参考您的APPLI阳离子以及随后的个人访谈,
我们很高兴地通知您已被选中参加工作..
(以下简称公司)。
我们很高兴为您提供以下就业机会。
< / a1 >
< / p1 >
< / Doc >





这是我的代码xslt



 <? xml version =   1.0 encoding =   utf-8 ?>  
< xsl: style sheet 版本 = 1.0 xmlns:xsl = http://www.w3.org/1999/XSL/Transform

xmlns:msxsl = urn:schemas-microsoft-com:xslt exclude-result-prefixes = msxsl >

< xsl:template 匹配 = / >
< html >
< body >
< h2 style = text-align :center; > 优惠信< / h2 >
< h3 style = text-align:对; margin-right:110px; > 参考编号:K070813 < / h3 >
< < span class =code-leadattribute> h3 style = text-align:Right; margin-right:224px; > 日期:< / h3 >
< h3 style = text-align:Left; margin-left:50px; > < / 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; > 亲爱的先生< / h3 >

< xsl:for-each 选择 = 文档/ p1 >
< h3 < span class =code-attribute> style = text-align:Left; margin-left:50px; >
< xsl:value-of select = a1 / >
< / h3 >
< / xsl:for-each >
< / body >
< / html >







这里是我的TransferXML()之类的..



  public   static   void  TransformXML()
{
// 使用默认凭据创建解析程序。

XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

// 将OfferLetter.xml文件转换为HTML
XslTransform transform = new XslTransform();

// 加载样式表文件:

transform.Load(HttpContext.Current.Server.MapPath( OfferLetter.xslt));

// 执行转换
transform.Transform(< span class =code-string> @ .. \ OffffetLetter.xml @ .. \ OffffLetter.html,解析器);

// 将OfferLetter.xml文件转换为逗号分隔格式
// 加载样式表

transform.Transform(HttpContext。 Current.Server.MapPath( OfferLetter.xslt), @ .. \ OffffetLetter.html,解析器);
}

解决方案

这个对我有用......

 <?  xml    < span class =code-summarycomment> version   =  1.0   编码  =  utf-8  >  
< xsl:stylesheet version = 1.0 xmlns:xsl = http://www.w3.org/1999/XSL/Transform xmlns:m = http://www.w3.org/1998/Math/ MathML

xmlns:qti = http://www.imsglobal.org / xsd / imsqti_v2p1 >
< xsl:output method = xml inden t = / >

< xsl:template 匹配 = / >
< xsl:apply-templates / >
< / xsl:template >
< xsl:template match = qti:p1 >
< xsl:copy-of 选择 = / >
< / xsl:template >
< / xsl:stylesheet >







oR



 <?  xml     version   =  1.0   编码  =  utf-8  >  
< xsl:stylesheet version = 1.0 xmlns:xsl = http://www.w3.org/1999/XSL/Transform < span class =code-attribute> xmlns:m = http://www.w3.org/1998/Math/MathML

xmlns:qti = http://www.imsglobal.org/xsd/imsqti_v2p1 >
< xsl:output 方法 = xml indent = / >
< xsl:template 匹配 = / >
< xsl:apply-templates / >
< / xsl:template >
< span class =code-keyword>< / xsl:stylesheet >


<?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 is my code for 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>
    <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 is my TransferXML() like..

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);
}

解决方案

This one worked for me...

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML"

    xmlns:qti="http://www.imsglobal.org/xsd/imsqti_v2p1">
    <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>
  <xsl:template match="qti:p1">
    <xsl:copy-of select="." />
  </xsl:template>
</xsl:stylesheet>




oR

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML"

    xmlns:qti="http://www.imsglobal.org/xsd/imsqti_v2p1">
    <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>
</xsl:stylesheet>


这篇关于xslt没有从xml获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆