我有兴趣将xml文档中根元素的标记名称分配给xslt变量.例如,如果文档看起来像(减去DTD):
<foo xmlns="http://.....">
<bar>1</bar>
</foo>
Run Code Online (Sandbox Code Playgroud)
我想将字符串'foo'分配给xslt变量.有没有办法引用它?
谢谢,马特
目前可用的XSLT处理器有哪些支持XPath 2.0标准?
关于函数式编程语言的几个问题让我思考XSLT是否是一种函数式编程语言.如果没有,缺少哪些功能?XSLT 2.0是否缩短或缩小了差距?
我需要从输入文档复制到输出文档除了一个属性之外的所有属性.
我的输入是这样的:
<mylink id="nextButton" type="next" href="javascript:;" />
Run Code Online (Sandbox Code Playgroud)
我需要像这样的输出:
<a id="nextButton" href="javascript:;" />
Run Code Online (Sandbox Code Playgroud)
如果我使用以下XSL:
<xsl:template match="mylink">
<a><xsl:copy-of select="attribute::*"/></a>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我得到所有属性输出如下:
<a id="nextButton" type="next" href="javascript:;" />
Run Code Online (Sandbox Code Playgroud)
但我想忽略"类型"属性.我尝试过以下但是它们似乎都没有按照我需要的方式工作:
<xsl:copy-of select="attribute::!type"/>
<xsl:copy-of select="attribute::!'type'"/>
<xsl:copy-of select="attribute::*[!type]"/>
<xsl:copy-of select="attribute::not(type)"/>
Run Code Online (Sandbox Code Playgroud)
我应该如何编写样式表以获得所需的输出?
我正在将一种格式的XML转换为另一种格式,我需要插入一个元素并将其命名为变量值.例如,我正在尝试使用XSLT的下面的语句,但我从处理器收到一个错误,说元素名称无效.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="no" omit-xml-declaration="no"/>
<xsl:variable name="i" select="i"/>
<xsl:variable name="b" select="b"/>
<xsl:variable name="u" select="u"/>
<xsl:variable name="s" select="s"/>
<xsl:variable name="r" select="r"/>
<xsl:variable name="m" select="m"/>
<xsl:variable name="n" select="n"/>
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="//w:r">
<xsl:if test="not(./descendant::w:i)">
<xsl:variable name="i">0</xsl:variable>
</xsl:if>
<xsl:if test="not(./descendant::w:b)">
<xsl:variable name="b">0</xsl:variable>
</xsl:if>
<xsl:if test="not(./descendant::w:u)">
<xsl:variable name="u">0</xsl:variable>
</xsl:if>
<xsl:if test="not(./descendant::w:caps)">
<xsl:variable name="c">0</xsl:variable>
</xsl:if>
<xsl:if test="not(contains($i,'0'))">
<xsl:variable name="r" …Run Code Online (Sandbox Code Playgroud) 比方说,如果有一个文件被调用data.xml,而一个文件是format.xsl(或者是format.xml?),即使用CSS转换XML数据并将其格式化,那么哪个浏览器可以显示它?应该打开哪个文件?(.xsl或.xml?)
实际上我在另一个例子中看到XSLT文件的第一行是href="format.xsl",所以我认为XSLT文件已经是.xsl?那怎么会链接到另一个.xsl文件?有多少个文件,2个或3个?
什么是XPath表达式,我将用于获取每本书的'HarryPotter:'之后的字符串.
即.鉴于此XML:
<bookstore>
<book>
HarryPotter:Chamber of Secrets
</book>
<book>
HarryPotter:Prisoners in Azkabahn
</book>
</bookstore>
Run Code Online (Sandbox Code Playgroud)
我会回来的:
Chamber of Secrets
Prisoners in Azkabahn
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情:
/bookstore/book/text()[substring-after(. , 'HarryPotter:')]
Run Code Online (Sandbox Code Playgroud)
我认为我的语法不正确......
我正在尝试使用Java Servlet创建RESTful Web服务.问题是我必须通过POST方法传递给Web服务器请求.此请求的内容不是参数,而是正文本身.
所以我基本上从ruby发送这样的东西:
url = URI.parse(@host)
req = Net::HTTP::Post.new('/WebService/WebServiceServlet')
req['Content-Type'] = "text/xml"
# req.basic_auth 'account', 'password'
req.body = data
response = Net::HTTP.start(url.host, url.port){ |http| puts http.request(req).body }
Run Code Online (Sandbox Code Playgroud)
然后我必须在我的servlet中检索此请求的主体.我使用经典的readline,所以我有一个字符串.问题是我必须将其解析为XML:
private void useXML( final String soft, final PrintWriter out) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, FileNotFoundException {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(soft);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//software/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList …Run Code Online (Sandbox Code Playgroud) 我是XSLT的新手,任何人都可以告诉我如何比较来自xml的两个元素作为字符串,它们的值是:
<OU_NAME>Vision Operations</OU_NAME> --XML code
<OU_ADDR1>90 Fifth Avenue</OU_ADDR1> --XML code
<xsl:choose>
<xsl:when test="OU_NAME='OU_ADDR1'"> --comparing two elements coming from XML
<!--remove if adrees already contain operating unit name
<xsl:value-of select="OU_NAME"/> <fo:block/>-->
<xsl:if test="OU_ADDR1 !='' ">
<xsl:value-of select="OU_ADDR1"/>
<fo:block/>
</xsl:if>
<xsl:if test="LE_ADDR2 !='' ">
<xsl:value-of select="OU_ADDR2"/>
<fo:block/>
</xsl:if>
<xsl:if test="LE_ADDR3 !='' ">
<xsl:value-of select="OU_ADDR3"/>
<fo:block/>
</xsl:if>
<xsl:if test="OU_TOWN_CITY !=''">
<xsl:value-of select="OU_TOWN_CITY"/>,
<fo:leader leader-pattern="space" leader-length="2.0pt"/>
</xsl:if>
<xsl:value-of select="OU_REGION2"/>
<fo:leader leader-pattern="space" leader-length="3.0pt"/>
<xsl:value-of select="OU_POSTALCODE"/>
<fo:block/>
<xsl:value-of select="OU_COUNTRY"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="OU_NAME"/>
<fo:block/>
<xsl:if test="OU_ADDR1 …Run Code Online (Sandbox Code Playgroud) 我从未在SQL Server 2008中使用过XML,我需要将客户列表提取到变量表中,您是如何做到的?
鉴于我CustomerList在Sales表格中调用的列如下所示,如何在sql中提取客户列表?
<ArrayOfCustomers xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Customer>
<ItemId>1</ItemId>
<Value>Mr Smith</Value>
</Customer>
<Customer>
<ItemId>2</ItemId>
<Value>Mr Bloggs</Value>
</Customer>
</ArrayOfCustomers>
Run Code Online (Sandbox Code Playgroud)