对于想了解html–xslt需要选择单引号的读者,本文将提供新的信息,我们将详细介绍html单引号双引号,并且为您提供关于178.html中单引号,双引号转义、C#使用XSLT实现xsl、xml与ht
对于想了解html – xslt需要选择单引号的读者,本文将提供新的信息,我们将详细介绍html 单引号 双引号,并且为您提供关于178. html 中单引号,双引号转义、C#使用XSLT实现xsl、xml与html相互转换、html – XSLT按属性值排序、HTML – 如何转换 在XSLT中的有价值信息。
本文目录一览:- html – xslt需要选择单引号(html 单引号 双引号)
- 178. html 中单引号,双引号转义
- C#使用XSLT实现xsl、xml与html相互转换
- html – XSLT按属性值排序
- HTML – 如何转换 在XSLT中
html – xslt需要选择单引号(html 单引号 双引号)
<xsl:with-param name="callme" select="'validateInput(this,'an');'"/>
我已经阅读了Escape single quote in xslt concat function,它告诉我要替换’with&’;我已经完成了它仍然没有工作..
有谁知道我们如何解决这个问题?:
<xsl:with-param name="callme" select="'validateInput(this,'an');'"/>
解决方法
<xsl:variable name="vApos">'</xsl:variable>
我经常使用相同的技术来指定引用:
<xsl:variable name="vQ">"</xsl:variable>
然后,您可以使用标准XPath函数concat()将任何这些变量散布到任何文本中:
concat('This movie is named ',$vQ,'Father',$vApos,'s secrets',$vQ)
所以,这个转变:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="vApos">'</xsl:variable> <xsl:variable name="vQ">"</xsl:variable> <xsl:template match="/"> <xsl:value-of select= "concat('This movie is named ',$vQ) "/> </xsl:template> </xsl:stylesheet>
生产:
This movie is named "Father's secrets"
178. html 中单引号,双引号转义
参考文档:https://blog.csdn.net/niu_hao/article/details/42319951
1. 效果
2. 需求
3. 具体代码
"
C#使用XSLT实现xsl、xml与html相互转换
XML文件
books.xml:
<xml version="1.0" encoding="utf-8" ?> <bookstore> <book genre="autobiography" publicationdate="1991" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore>
一、转为html文档
1、xsl文件
books.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <HTML> <head> <title>Price List</title> </head> <body> <table> <xsl:apply-templates/> </table> </body> </HTML> </xsl:template> <xsl:template match="bookstore"> <xsl:apply-templates select="book"/> </xsl:template> <xsl:template match="book"> <tr> <td> <xsl:value-of select="title"/> </td> <td> <xsl:value-of select="price"/> </td> </tr> </xsl:template> </xsl:stylesheet>
2、转换
将books.xml按照books.xsl定义的格式转换成out.html
XslCompiledTransform trans = new XslCompiledTransform(); trans.Load(@"..\..\books.xsl"); trans.Transform(@"..\..\books.xml", "out.html");
3、结果
out.html:
<HTML> <head> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Price List</title> </head> <body> <table> <tr> <td>The Autobiography of Benjamin Franklin</td> <td>8.99</td> </tr> <tr> <td>The Confidence Man</td> <td>11.99</td> </tr> <tr> <td>The Gorgias</td> <td>9.99</td> </tr> </table> </body> </HTML>
二、转为xml文档
1、prices.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myObj="urn:price-conv"> Price conversion factor <xsl:param name="conv" select="1.15"/> <xsl:template match="bookstore"> <bookstore> <xsl:for-each select="book"> <book> <xsl:copy-of select="node()"/> <new-price> <xsl:value-of select="myObj:NewPriceFunc(./price, $conv)"/> </new-price> </book> </xsl:for-each> </bookstore> </xsl:template> </xsl:stylesheet>
2、转换XsltArgumentList.AddExtensionObject
在以下示例中,样式表使用 XSLT 扩展对象要转换的书籍价格。
using System; using System.IO; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; public class Sample { public static void Main() { // Create the XslCompiledTransform and load the stylesheet. XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("prices.xsl"); // Create an XsltArgumentList. XsltArgumentList xslArg = new XsltArgumentList(); // Add an object to calculate the new book price. BookPrice obj = new BookPrice(); xslArg.AddExtensionObject("urn:price-conv", obj); using (XmlWriter w = XmlWriter.Create("output.xml")) { // Transform the file. xslt.Transform("books.xml", xslArg, w); } } // Convert the book price to a new price using the conversion factor. public class BookPrice{ private decimal newprice = 0; public decimal NewPriceFunc(decimal price, decimal conv){ decimal tmp = price*conv; newprice = decimal.Round(tmp, 2); return newprice; } } }
三 、调用XSL参数
1、xml文件
order.xml
Represents a customer order <order> <book ISBN=''10-861003-324''> <title>The Handmaid''s Tale</title> <price>19.95</price> </book> <cd ISBN=''2-3631-4''> <title>Americana</title> <price>16.95</price> </cd> </order>
2、order.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="date"/> <xsl:template match="/"> <order> <date><xsl:value-of select="$date"/></date> <total><xsl:value-of select="sum(//price)"/>total> </order> </xsl:template> </xsl:stylesheet>
3、转换
下面的示例使用AddParam方法来创建表示当前日期和时间的参数。
using System; using System.IO; using System.Xml; using System.Xml.Xsl; public class Sample { public static void Main() { // Create the XslCompiledTransform and load the stylesheet. XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("order.xsl"); // Create the XsltArgumentList. XsltArgumentList xslArg = new XsltArgumentList(); // Create a parameter which represents the current date and time. DateTime d = DateTime.Now; xslArg.AddParam("date", "", d.ToString()); // Transform the file. using (XmlWriter w = XmlWriter.Create("output.xml")) { xslt.Transform("order.xml", xslArg, w); } } }
四、使用 XML 控件
有时候你可能希望把带有其他内容的转换后的 HTML 输出和 Web 控件组合在一起,XML 控件在页面独立的部分显示 XSL 转换后的结果:
ID="Xml1" runat="server" DocumentSource="DvdList.xml" TransformSource="DvdList.xslt">
注意: 你也可以用编码中XmlDocument 对象赋给 Document 属性,或者把一个包含 XML 内容的字符串赋给 DocumentContent 属性,而不是使用 DocumentSource 属性。类似的,你可以一个 XslTransform 对象值赋给 Transform 属性来提供 XSLT 信息。
到此这篇关于C#使用XSLT实现xsl、xml与html相互转换的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。
- C#实现实体类和XML的相互转换
- C# XML字符串包含特殊字符的处理转换方法小结
- C#实现实体类和XML相互转换
- C#实现XML与实体类之间相互转换的方法(序列化与反序列化)
- C#实现将文件转换为XML的方法
- C#中使用JSON.NET实现JSON、XML相互转换
- C# XML与Json之间相互转换实例详解
- C#对象与XMl文件之间的相互转换
html – XSLT按属性值排序
我有一个关于如何基于属性值进行排序的问题.
我有以下源文档,我想按标题类值的值对轨道项进行排序.
希望有人可以帮助解决这个问题.
最终输出应如下所示:
我尝试了以下但它不起作用.
谢谢.
最佳答案
你可以这样做:
aration="yes"/>
copy>
copy>
copy>
copy>
在样本输入上运行时,结果为:
HTML – 如何转换 在XSLT中
我有一个以下xslt:
disable-output-escaping="yes">
改造后我得到:
它呈现为:&一些文字
我想渲染& NBSP;作为空间角色.我已经尝试过将disable-output-escaping改为no,但它没有帮助.
感谢帮助.
最佳答案
我认为你应该使用 ,因为& nbsp;实体很可能没有定义.而且没有CDATA.
还有一种可能性是为xsl文件定义实体:
我们今天的关于html – xslt需要选择单引号和html 单引号 双引号的分享已经告一段落,感谢您的关注,如果您想了解更多关于178. html 中单引号,双引号转义、C#使用XSLT实现xsl、xml与html相互转换、html – XSLT按属性值排序、HTML – 如何转换 在XSLT中的相关信息,请在本站查询。
本文标签: