如何使用XSL检查值是空还是空?
例如,如果categoryName
是空的?我在选择构造时使用的是.
例如:
<xsl:choose>
<xsl:when test="categoryName !=null">
<xsl:value-of select="categoryName " />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="other" />
</xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud) 在处理我的XML时,我正在尝试href
使用以下行将从属性引用的SVG文件直接复制到我的输出HTML中:
<xsl:copy-of copy-namespaces="yes" select="document(@href)"/>
Run Code Online (Sandbox Code Playgroud)
这copy-namespaces
不应该是必要的,因为无论如何默认值是"是",但我已添加它以防止我是否尝试过它的问题.
这些文件被复制到HTML中,但任何命名空间元素都会被清除.例如,在复制之前看起来像这样的文件:
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<g transform="translate(-519.21143,-667.79077)" id="layer1">
<image xlink:href="data:image/png;base64
Run Code Online (Sandbox Code Playgroud)
之后看起来像这样:
<_0:RDF xmlns:_0="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<_0:Work xmlns:_0="http://creativecommons.org/ns#" about="">
<_0:format xmlns:_0="http://purl.org/dc/elements/1.1/">image/svg+xml</_0:format>
<_0:type xmlns:_0="http://purl.org/dc/elements/1.1/" resource="http://purl.org/dc/dcmitype/StillImage"/>
<_0:title xmlns:_0="http://purl.org/dc/elements/1.1/"/>
</_0:Work>
</_0:RDF>
</metadata>
<g id="layer1" transform="translate(-519.21143,-667.79077)">
<image href="data:image/png;base64
Run Code Online (Sandbox Code Playgroud)
href
图像元素值上缺少的xlink命名空间特别成问题.
有关如何以不同方式执行此操作的任何想法,无需任何解释即可阅读SVG文件?
我找到了一个"有效"的解决方案,但它是一个黑客,我想要一些更优雅的东西:
<xsl:template name="topic-image-svg">
<!-- Generate tags to embed SWFs -->
<xsl:element name="div">
<xsl:if test="@width">
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@height">
<xsl:attribute name="height">
<xsl:value-of select="@height"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="document(@href)" mode="svg"/> …
Run Code Online (Sandbox Code Playgroud) 我是XSLT的新手,无法解决以下代码出错的问题.
<xsl:variable name="var" select="boolean('false')"/>
<xsl:if test="$var'">variable is true</xsl:if>
Run Code Online (Sandbox Code Playgroud)
当它意味着虚假时,它总是返回真实.为什么?
我真的不知道XSL但是我需要修复这个代码,我已经减少了它以使它更简单.
我收到了这个错误
无效的XSLT/XPath函数
在这条线上
<xsl:variable name="text" select="replace($text,'a','b')"/>
Run Code Online (Sandbox Code Playgroud)
这是XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inm="http://www.inmagic.com/webpublisher/query" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:preserve-space elements="*" />
<xsl:template match="text()" />
<xsl:template match="mos">
<xsl:apply-templates />
<xsl:for-each select="mosObj">
'Notes or subject'
<xsl:call-template
name="rem-html">
<xsl:with-param name="text" select="SBS_ABSTRACT" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="rem-html">
<xsl:param name="text" />
<xsl:variable name="text" select="replace($text, 'a', 'b')" />
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
谁能告诉我它有什么问题?
嗨,我已经执行了一个转换,如果它是null,则删除一个标记.
我想检查我的转换是否正常工作,所以不是手动检查,而是编写了一个XSLT代码,只检查OUTPUT XML中是否存在该特定标记,如果它为null,则第二个XSLT应该输出一个文字"发现".(我实际上并不需要一些XML类型的输出,但我只是使用XSLT进行搜索.)
当我尝试使用这个XSL代码::
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/SiebelMessage//SuppressCalendar[.!='']">
FOUND
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
它输出XML文件中存在的所有TEXT DATA,
为了避免这种情况,我不得不写下这段代码::
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/SiebelMessage//SuppressCalendar[.!='']">
FOUND
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
为什么以前的代码输出TEXT,为什么我要坚持XSL忽略所有其他文本?是所有XML解析器的行为或仅我自己的行为(我正在使用msxml解析器).
在
<xsl:template name="temp_name" mode="mode">
Run Code Online (Sandbox Code Playgroud)
是什么意思mode
?我搜索了很多资源,但我找不到这方面的例子.那么有人可以用一个例子解释一下吗?提前致谢.
我有很多XML文件,它们具有以下形式:
<Element fruit="apple" animal="cat" />
Run Code Online (Sandbox Code Playgroud)
我想从文件中删除.
使用XSLT样式表和Linux命令行实用程序xsltproc,我该怎么做?
到目前为止,在脚本中我已经有了包含我想要删除的元素的文件列表,因此单个文件可以用作参数.
编辑:这个问题原本缺乏意图.
我想要实现的是删除整个元素"元素",其中(fruit =="apple"&& animal =="cat").在同一文件中有许多名为"元素"的元素,我希望这些元素保留下来.所以
<Element fruit="orange" animal="dog" />
<Element fruit="apple" animal="cat" />
<Element fruit="pear" animal="wild three eyed mongoose of kentucky" />
Run Code Online (Sandbox Code Playgroud)
会成为:
<Element fruit="orange" animal="dog" />
<Element fruit="pear" animal="wild three eyed mongoose of kentucky" />
Run Code Online (Sandbox Code Playgroud) 从XSLT 1.0升级到2.0涉及什么?
1 - 升级的可能原因是什么?
2 - 不升级的可能原因是什么?
3 - 最后,升级的步骤是什么?
我希望有一个执行摘要 - 简短的版本:)
我有一个XML文档,我想更改其中一个属性的值.
首先,我使用以下方法复制从输入到输出的所
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
现在我想"type"
在任何名为的元素中更改属性的值"property"
.
我只是在学习XML以及如何使用XSL文件.在XSL文件中,我发现了以下术语:
xsl:template match="/"
Run Code Online (Sandbox Code Playgroud)
这代表什么?我可以用什么而不是/
?我可以写table
或任何其他HTML标签而不是/
?