我在使用XSLT转换的java应用程序下工作.我有很多document()调用,所以有可能有java.lang.OutOfMemory异常(我实际上有),因为在每次调用document()函数之后,文档都会被缓存.
在http://xml.apache.org/xalan-j/faq.html#faq-N102F9,我读到可以增加堆内存大小,这在我的情况下不是解决方案.我也尝试使用似乎不支持的增量变换.
那么,有没有可能在使用document()函数时关闭jaxp中的文档缓存?
我试图动态地在Java中创建一个XML文件来显示时间表.我为我的XML文件创建了一个DTD,我有一个我想用来转换XML的XSL文件.我不确切知道如何继续.
我到目前为止所尝试的是点击一个按钮,调用一个Servlet,它生成XML文件内容的字符串(将XML的动态部分插入到String中.我现在有一个包含XML内容的String我现在想使用我服务器上的XSL文件转换XML文件,并在调用Servlet的页面中显示结果(通过AJAX执行此操作).
我不确定我是否在这个方向,也许我甚至不应该从一开始就以String形式创建XML代码.所以我的问题是,我如何从这里继续?如何使用XSL文件转换XML字符串,并将其作为对AJAX调用的响应发送,以便将生成的代码植入页面?或者,如果这不是这样做的,那么如何以不同的方式创建动态XML文件以产生相同的结果?
就我而言,我有:
<booklist>
<book id="1">
</book>
<book id="2">
</book>
<book id="3">
</book>
......
</booklist>
Run Code Online (Sandbox Code Playgroud)
我怎么才能回来:
<booklist>
<book id="1">
</book>
</booklist>
Run Code Online (Sandbox Code Playgroud)
如果我使用/booklist/book[@id=1],我只能得到
<book id="1">
</book>
Run Code Online (Sandbox Code Playgroud)
但我还需要文档元素.谢谢
你可以在模板中调用模板吗?例如:
如果我想要使用
<xsl:choose>
<xsl:when test="//*[local-name()='RetrieveCCTransRq']">
<xsl:call-template name="SOAPOutput"/>
</xsl:when>
</xsl:choose>
<xsl:template name="SOAPOutput">
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<OutputPayload>
<TotalTransactions>
<xsl:value-of select="count(//Transaction)"/>
</TotalTransactions>
<Transactions>
<xsl:apply-templates/>
</Transactions>
</OutputPayload>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<xsl:template match="Transaction">
<xsl:choose>
<xsl:when test="contains(Type,'Debit')">
<Debit>
<xsl:apply-templates select="Date"/>
<xsl:apply-templates select="PostDate"/>
<xsl:apply-templates select="Description"/>
<xsl:apply-templates select="Amount"/>
</Debit>
</xsl:when>
<xsl:otherwise>
<Credit>
<xsl:apply-templates select="Date"/>
<xsl:apply-templates select="PostDate"/>
<xsl:apply-templates select="Description"/>
<xsl:apply-templates select="Amount"/>
</Credit>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Date">
<Date>
<xsl:value-of select="."/>
</Date>
</xsl:template>
<xsl:template match="PostDate">
<PostDate>
<xsl:value-of select="."/>
</PostDate>
</xsl:template>
<xsl:template match="Description">
<Description>
<xsl:value-of select="."/>
</Description>
</xsl:template>
<xsl:template match="Amount">
<Amount>
<xsl:value-of select="."/> …Run Code Online (Sandbox Code Playgroud) 我想使用powershell对以下xml文档进行排序.
<car>
<germany>
<manufacturer>Opel</manufacturer>
<manufacturer>BMW</manufacturer>
<manufacturer>Benz</manufacturer>
</germany>
<japan>
<manufacturer>Nissan</manufacturer>
<manufacturer>Daihatsu</manufacturer>
</japan></car>
Run Code Online (Sandbox Code Playgroud)
因此,应该对德国和日本内部的元素进行排序.
理想情况下,我想从文件系统中读取xml,并使用已排序的文档覆盖现有文档.
我的理解是,尽管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)
所以"|" 实际上,运算符不遵循节点集操作数的顺序.有没有办法可以连接节点集,以便顺序得到尊重?
据我所知,使用空字符串作为参数的XSLT函数document()应该读取当前的XSLT文档.但是以下代码不起作用:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<state>test2</state>
<xsl:template match="/">
test1
<xsl:value-of select="document('')/*/state"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
当我将这个XSLT应用于某些XML(仅作为示例)时,我只有"test1"作为输出.为什么排队
<xsl:value-of select="document('')/*/state"/>
Run Code Online (Sandbox Code Playgroud)
不打印"test2"?
在我的样式表中,我尝试将输入参数的默认值设置为以点字符开头的字符串。并且总是收到错误代码 0x8004005 - 预期的 toden 'eof' 找到 'NAME'。例如:
<xsl:param name="p1" select=".exe"/>
Run Code Online (Sandbox Code Playgroud)
然而,点后面的内容并不重要。总是同样的错误。如何形成该字符串以包含第一个点?
在做类似的事情时/entries/entry/key='test',我总是得到返回的节点密钥.但我想要入口节点.我怎么才能得到它?
我的XML看起来像这样:
<entries>
<entry>
<key>test</key>
</entry>
</entries>
Run Code Online (Sandbox Code Playgroud) 如何使用XPath表达式查找具有两个可能类名的元素?
我正在使用Python,Selenium我希望找到所有class具有两个可能名称之一的元素.
'//div[@class="list"]/div[@class="item ng-scope highlight"]//h3/a[@class="ng-binding"]'
当然,我可以进行两次单独的搜索,并将结果连成一个列表.但是有一种更简单有效的方法.也许通过使用|.