我的理解是,尽管XSLT的"节点集"被称为"集合",但它们实际上是有序的节点列表(这就是每个节点与索引相关联的原因).我因此一直试图使用"|" 运算符以连接节点集,以便遵守节点的顺序.
我试图完成的是类似下面的JavaScript代码:
[o1,o2,o3].concat([o4,o5,o6])
Run Code Online (Sandbox Code Playgroud)
产量:
[o1,o2,o3,o4,o5,o6]
Run Code Online (Sandbox Code Playgroud)
但是,请考虑以下简化示例:
testFlatten.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:variable name="parentTransition" select="//*[@id='parentTransition']"/>
<xsl:variable name="childTransition" select="//*[@id='childTransition']"/>
<xsl:variable name="parentThenChildTransitions" select="$parentTransition | $childTransition"/>
<xsl:variable name="childThenParentTransitions" select="$childTransition | $parentTransition"/>
<return>
<parentThenChildTransitions>
<xsl:copy-of select="$parentThenChildTransitions"/>
</parentThenChildTransitions>
<childThenParentTransitions>
<xsl:copy-of select="$childThenParentTransitions"/>
</childThenParentTransitions>
</return>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
鉴于以下输入:
<?xml version="1.0"?>
<root>
<element id="parentTransition"/>
<element id="childTransition"/>
</root>
Run Code Online (Sandbox Code Playgroud)
产量(使用xsltproc):
<?xml version="1.0"?>
<return>
<parentThenChildTransitions>
<element id="parentTransition"/><element id="childTransition"/>
</parentThenChildTransitions>
<childThenParentTransitions>
<element id="parentTransition"/><element id="childTransition"/>
</childThenParentTransitions>
</return>
Run Code Online (Sandbox Code Playgroud)
所以"|" 实际上,运算符不遵循节点集操作数的顺序.有没有办法可以连接节点集,以便顺序得到尊重?
是否有可能编写一个XPath表达式来获取节点集中节点的根节点,该节点集仅包含对节点的引用?
使用"/"对我来说不起作用,因为它只引用输入文档根目录.此外,我希望它在没有上下文的情况下工作,并将其用于可在处理期间动态创建的通用节点集.
例如...
<xsl:function name="my:getRoot">
<xsl:param name="n" />
<xsl:variable name="rootnode" select="some_solution($n)"/>
</xsl:function>
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
XPath 2.0 preceding::
和ancestor::
XPath 2.0 之间的区别是什么?
我有以下 XML:
<xml>
<entry key="e1" value="foo"/>
<entry key="e2" value="bar"/>
...
</xml>
Run Code Online (Sandbox Code Playgroud)
我想从 XPath 获得以下输出:
e1: foo, e2: bar, ...
Run Code Online (Sandbox Code Playgroud)
我尝试使用,string-join
但没有用。任何想法哪个版本的 XPath 可以做到这一点?甚至有可能吗?
(注意:我更喜欢 XPath 1.0 查询,但是,我认为这是不可能的)
我试图在xPath 2.0中使用函数将xs:double转换为xs:integer(我不想使用XSLT).
number(//version//number/text())
Run Code Online (Sandbox Code Playgroud)
以上输出为 - 6.0(取数为6.0).我如何将其转换为6?
当我运行 XQuery 命令行时,只要结果是一个元素,它就可以工作。
当我扩展该 XQuery 以仅获取属性值时,它失败并显示以下错误:
SENR0001: Cannot serialize a free-standing attribute node (net.sf.saxon.om.NameOfNode)
Run Code Online (Sandbox Code Playgroud)
所以,这有效
java -cp ...Saxon-HE-9.9.0-1.jar net.sf.saxon.Query
-s:AnyXMLFileAvailable.xml -qs:/
Run Code Online (Sandbox Code Playgroud)
这失败了:
java -cp ...Saxon-HE-9.9.0-1.jar net.sf.saxon.Query
s:AnyXMLFileAvailable.xml -qs://@*
Run Code Online (Sandbox Code Playgroud)
只要 XML 中的任何地方至少有一个属性,此命令就会失败并出现上述错误
我相信这可以通过许可的撒克逊人来解决,它可以使用
-outval:recover
Run Code Online (Sandbox Code Playgroud)
转变。还有其他方法吗?
我在尝试创建 Telegram 的 Instant View 模板时遇到问题,出现以下错误:
Element <img> is not supported in <p>: <img src="mysrc" />
Run Code Online (Sandbox Code Playgroud)
所以,<p>
如果有<img>
标签,我决定用标签替换<figure>
标签
@replace_tag(<figure>): $body//p//img
但结果没有显示图像。仅供参考,<img>
除了src
.
示例代码:
<p><img src="mysrc"/></p>
Run Code Online (Sandbox Code Playgroud)
我不知道,请帮助我
错误:
处理您的模板时发生错误
代码:
Element <img> is not supported in <a>: <img alt="" data-src="https://secure.gravatar.com/avatar/3351cc569871d023d58bcd1029b48437?s=26&d=mm&r=g" class="avatar avatar-26 photo avatar-default" height="26" width="26"/>
Run Code Online (Sandbox Code Playgroud)
我正在使用 xslt 2.0 和 Saxon 9.6,需要将价格金额和数量相乘,然后将结果四舍五入到小数点后两位。我不想要银行四舍五入,我想要四舍五入所以 .495 = 0.50 和 .494 = .49 。我尝试阅读有关此问题的几篇文章和帖子,但找不到解决方案。我看到几个地方由于浮点问题而使用 xslt 1.0 进行舍入是有问题的,并且很多人提到 xslt 2.0 和 xs:decimal 应该可以解决问题,但我似乎找不到“防水”解决方案。
我有一个 xml 文件(发票),其中包含 4 个不同的 InvoiceLines,其中包含价格和数量元素:
<Invoice>
<ID>12345</ID>
<IssueDate>2012-11-21</IssueDate>
<Supplier>
<Party>
<ID>977187761</ID>
</Party>
</Supplier>
<Customer>
<Party>
<ID schemeID="NO:ORGNR">810305282</ID>
</Party>
</Customer>
<Delivery>
<DeliveryDate>2012-11-21</DeliveryDate>
</Delivery>
<TaxTotal>
<TaxAmount currencyID="NOK">128.89</TaxAmount>
</TaxTotal>
<InvoiceLine>
<ID>1</ID>
<Quantity unitCode="EA">19</Quantity>
<LineAmount currencyID="NOK">130.26</LineAmount>
<Item>
<Name>TestItem</Name>
</Item>
<Price currencyID="NOK">8.569736842105263</Price>
</InvoiceLine>
<InvoiceLine>
<ID>2</ID>
<Quantity unitCode="NAR">1.00</Quantity>
<LineAmount currencyID="NOK">128.2</LineAmount>
<Item>
<Name>Vare A</Name>
</Item>
<Price currencyID="NOK">128.195</Price>
</InvoiceLine>
<InvoiceLine>
<ID>3</ID>
<Quantity unitCode="NAR">1.00</Quantity>
<LineAmount currencyID="NOK">128.7</LineAmount> …
Run Code Online (Sandbox Code Playgroud) 我的问题是引述获得的值获取属性(“CF”)在
<property expression="fn:concat(get-property('whereConcat'),' AND PA_INATO=', get-property('cf'))" name="whereConcat" scope="default" type="STRING"/>
我尝试了不同的方式(字符编码:'
,字符转义:),\'
但没有成功。