xslt 相关问题

XSLT是XML的一种转换语言,旨在将结构化文档转换为其他格式(如XML,HTML和纯文本,或者在XSLT 3,JSON中)。问题应该根据需要使用xslt-1.0,xslt-2.0或xslt-3.0标记之一。

XSL/XSLT - 动态获取父节点及其值

有人可以帮助我吗?我有一个 xml,可以在其中获取节点中节点的名称,例如值、宽度、高度、重量…… 例子: 有人可以帮助我吗?我有一个 xml,可以在其中获取节点中节点的名称,例如值、宽度、高度、重量…… 示例: <?xml version="1.0" encoding="utf-8"?> <Data totalExecutionTime="00:00:00.0076034" totalCount="1">   <Features>     <ProductID id="100" language="NLB" caption="Product ID" captionAlternative="Product ID" unit="" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="" viewGroup="" viewGroupOrder="0" topViewGroupId="b65b432a-1bf1-4fd4-ae92-03418d3204be" topViewGroup="Algemeen" topViewGroupOrder="1" viewOrder="0" form="Complex" dataType="String" readOnly="False" />     <Length id="245" language="NLB" caption="Lengte" captionAlternative="Lengte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="1" form="Simple" dataType="Number" readOnly="False" />     <Width id="242" language="NLB" caption="Breedte" captionAlternative="Breedte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="2" form="Simple" dataType="Number" readOnly="False" />     <Height id="244" language="NLB" caption="Hoogte" captionAlternative="Hoogte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="3" form="Simple" dataType="Number" readOnly="False" />     <Depth id="771" language="NLB" caption="Diepte" captionAlternative="Diepte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="4" form="Simple" dataType="Number" readOnly="False" />     <Weight id="243" language="NLB" caption="Gewicht" captionAlternative="Gewicht" unit="kg" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="5" form="Simple" dataType="Number" readOnly="False" />     <LoadCapacity id="457" language="NLB" caption="Draagvermogen" captionAlternative="Draagvermogen" unit="kg" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="c9d7dd7e-8a85-47cc-8542-2695e4615f75" viewGroup="Technische specificaties" viewGroupOrder="15" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="6" form="Simple" dataType="Number" readOnly="False" />     <Volume id="435" language="NLB" caption="Inhoud" captionAlternative="Inhoud" unit="l" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="bfaf678b-8b9d-4cea-aa99-08edd8316dc7" viewGroup="Algemene specificaties" viewGroupOrder="13" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="7" form="Simple" dataType="Number" readOnly="False" />     <TireSize id="705" language="NLB" caption="Banden maat" captionAlternative="Banden maat" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="c9d7dd7e-8a85-47cc-8542-2695e4615f75" viewGroup="Technische specificaties" viewGroupOrder="15" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="8" form="Simple" dataType="String" readOnly="False" />     <LoadingScoop id="706" language="NLB" caption="Laadschep" captionAlternative="Laadschep" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="c9d7dd7e-8a85-47cc-8542-2695e4615f75" viewGroup="Technische specificaties" viewGroupOrder="15" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="9" form="Simple" dataType="String" readOnly="False" />   </Features>   <ProductID id="25137" parentId="0" brand="Normal" order="0" createdDate="2020-03-24T15:30:07.21" modifiedDate="2023-11-20T20:01:33.87">     <Value seq="0" modifiedDate="2020-03-24T15:30:10.493">111TA5851</Value>     <Width seq="0" modifiedDate="2020-03-24T15:30:10.493">515</Width>     <Height seq="0" modifiedDate="2020-03-24T15:30:10.493">1100</Height>     <Weight seq="0" modifiedDate="2020-04-02T13:18:09.44">7.7</Weight>     <LoadCapacity seq="0" modifiedDate="2020-03-24T15:30:10.493">150</LoadCapacity>     <LoadingScoop seq="0" modifiedDate="2020-03-24T15:30:10.493">350x170</LoadingScoop>   </ProductID> </Data> 我想要的是动态获取对应父节点的值。我可以获得如下节点名称: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <table> <xsl:for-each select="/Data/ProductID/*"> <xsl:variable name="myVariable" select="name(.)"/> <xsl:variable name="HasValue" select="count(/Data/ProductID/*)" /> <tr> <td><xsl:value-of select="name(.)" /></td> <td><xsl:value-of select="local-name()" /></td> <td><xsl:value-of select="name()" /></td> <td><xsl:value-of select="/Data/node($myVariable)/@unit" /></td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> 但我不知道如何获取响应的父节点及其值,例如单位元素。 提前致谢并致以诚挚的问候 我已经尝试过但没用。我会不断收到错误:解析 '' 期间出现意外的标记 '$myVariable'。 我想你想声明一把钥匙 <xsl:key name="element-key" match="Data/Features" use="name()"/> 然后你想使用例如key('element-name', name())/@unit。

回答 1 投票 0

如何使用xslt将xml中的文本转换为html中的超链接

如何使用 xslt 将 xml 中的文本转换为 html 中的超链接。 我的 Xml 代码是 C:\测试\CaptureF15165617TC001_05_06_1516_57_11.png 如何使用 xslt 将 xml 中的文本转换为 html 中的超链接。 我的Xml代码是 <Steps> <Filepath>C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</Filepath> </Steps> 将其转换为 html,我的 xslt 代码如下 <td width='15%'> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="./Filepath"/> </xsl:attribute> <xsl:value-of select="./Filepath"/> </xsl:element> </td> 现在这段代码在html中写入文件的整个路径,但我只想在html中写入“文件”以及指向文件位置的超链接。 我当前生成的html代码如下 C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png <td width="15%"><a href="C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png">C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</a></td> 我想要的是 <td width="15%"><a href="C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png">File</a></td> 任何人都可以帮助我需要在 xslt 中进行哪些更改。 你告诉它具有价值: <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="./Filepath"/> </xsl:attribute> <xsl:value-of select="./Filepath"/> <!--This is the link text --> </xsl:element> 所以将其更改为: <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="./Filepath"/> </xsl:attribute> File </xsl:element> 或者简短地说: <a href="{Filepath}">File</a> <Steps> <Filepath>C:\Test\Capture\050615165617TC001_05_06_1516_57_11.png</Filepath> </Steps>

回答 3 投票 0

如何从xs:duration中提取毫秒?

我想从 XSLT 中的 xs:duration 中提取毫秒。 使用格式日期时间() XML: PT0.0032S XSLT: 我想从 XSLT 中的 xs:duration 中提取毫秒。 使用 format-dateTime() XML: <exposure_time>PT0.0032S</exposure_time> XSLT: <xsl:variable name="seconds" select="format-dateTime(exposure_time, '[s01].[f0001]')"/> 编译时出错: Transformation failure: Error XPTY0004 at webpage.xslt#98 Supplied value "PT0.0032S" is not a valid xs:dateTime Error XPTY0004 at webpage.xslt#98 Supplied value "PT0.0032S" is not a valid xs:dateTime 使用持续时间秒数() seconds-from-duration(exposure_time) 返回 0,我想得到 0.0032。 在您的示例中,函数 seconds-from-duration() 应返回 0.0032 - 只不过结果的精度在某种程度上是由实现定义的。 我正在查看https://www.w3.org/TR/xpath-functions-31/的规范,据我所知(我可能错过了一些东西)第9.1.1节规定所有处理器必须支持毫秒精度或更高的日期和时间,但我没有看到类似的持续时间声明。 您实际使用的 XSLT 实现(和版本)是什么? 正如其他人已经指出的那样,表达式: seconds-from-duration(exposure_time) 应该给你你需要的结果。 如果由于某种原因没有,您可以尝试使用 format-dateTime() 函数,但首先您需要将 dayTimeDuration 值转换为有效的 dateTime。只需将其添加到具有空(午夜)时间组件的任意日期的 dateTime 即可完成此操作: format-dateTime(xs:dateTime('2024-01-01T00:00:00') + xs:dayTimeDuration(exposure_time), '[s1].[f0001]')

回答 2 投票 0

如何在xslt-1.0中从xml变量中选择元素?

我这里有一个xslt转换,包括这个: 我这里有一个 xslt 转换,包括这个: <xsl:variable name="mydict"> <dict> <entry name="a" value="1"/> <entry name="b" value="2"/> <entry name="c" value="3"/> <entry name="d" value="4"/> </dict> </xsl:variable> 可行,我可以将其称为 $mydict,例如,用 <xsl:copy-of select="$mydict"/> 打印它。 但是,从那一刻起,如果我想实际使用它来做某事,更清楚的是,如果我想将它用作字典,事情就会变得丑陋。或者地图。或者字符串索引的字符串数组。 例如,如果我有另一个值为 3 的变量,我怎样才能得到 "c"? 我对$mydict//entry[@name="$c"]和类似的尝试都因各种症状而失败。我认为,问题可能根源在于 $mydict 就像一个字符串而不是一个节点,我可以在其中执行各种操作(最重要的是,通过 xpath 查询引用其部分)。 我这里有一个 xsltproc 命令行工具,我很乐意继续使用它,但如果没有更好的方法,可以切换到最新的 saxon。 好的,我已经找到解决方案了。 node-set 函数执行此操作,然后执行 a <xsl:copy-of select="exsl:node-set($mydict)//dict/type[@name='$idx']"/> 会做我想做的事。重要的是: node-set($mydict)可以将$mydict从xml变量转换为实际节点。作为一个节点集,它也可以有多个顶级节点。 node-set() 不是基本 xslt 的一部分,但它是一个扩展。幸运的是,xsltproc 支持此扩展,但它需要在其 <xml 命名空间标头中进行声明,大致如下: 之后,我们的 node-set() 方法为 exsl:node-set。

回答 1 投票 0

XPath 方括号运算符产生意外结果

考虑这个 XML 文档: 我正在努力寻找第一个<...

回答 1 投票 0

使用 Muenchian 方法排序来获取最小值和最大值的 XSLT 聚合

我理解慕尼黑方法在第一次阅读时索引了整个文档。但如何才能在分组之前或分组内排序而不是按其键排序呢?具体来说,我如何订购...

回答 2 投票 0

显示范围内的XML节点?

在任何地方都没有找到这个,所以我在这里问。 我有一个 xml 文档,结构如下: 第 1 行 第2行 第 3 行 在任何地方都没有找到这个,所以我在这里问。 我有一个 xml 文档,结构如下: <root> <row>Row 1</row> <row>Row 2</row> <row>Row 3</row> <row>Row 4</row> <row>Row 5</row> <row>Row 6</row> <row>Row 7</row> <row>Row 8</row> <row>Row 9</row> <row>Row 10</row> </root> 在xsl文档中,我想显示一个范围内的行。例如,我想只显示从Row 3到Row 8的行,不包括第一行和最后两行。 我知道如何设置行数限制,但显示从 Row 1(第一个)开始的行。 编辑:错别字 您可以使用基于位置的谓词: select="row[position() >= 3 and position() &lt;= 8]" 这可能位于 xsl:apply-templates 或 xsl:for-each 中,甚至位于 xsl:copy-of 指令中(全部来自 root 的上下文)。您没有发布您的尝试或预期结果,所以我们只能猜测。

回答 1 投票 0

如何循环遍历特定标签并将其逐行显示?

我是 XSLT 的初学者。我正在尝试使用 Apache FOP 创建 AFP 文档。 我有一个像这样的输入 XML: 测试 <...

回答 1 投票 0

在 Saxon XSLT 中收集处理期间获取文件名

我正在尝试使用 XSL-T 处理充满 SVG 文件的目录。我目前已经尝试过: 我正在尝试使用 XSL-T 处理充满 SVG 文件的目录。我目前已经尝试过: <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns="http://www.w3.org/2000/svg" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://www.w3.org/2000/svg" exclude-result-prefixes="xsl"> <xsl:output method="xml" doctype-public="-//W3C//DTD SVG 1.1//EN http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"/> <xsl:strip-space elements="*"/> <xsl:template name="main"> <svg xmlns="http://www.w3.org/2000/svg"> <defs/> <xsl:apply-templates select="collection(concat(resolve-uri('src/images'),'?select=*.svg;content-type=application/xml'))"/> </svg> </xsl:template> <xsl:template match="/"> <xsl:apply-templates select="svg"/> </xsl:template> <xsl:template match="svg"> <xsl:element name="symbol"> <xsl:attribute name="id"><xsl:value-of select="tokenize(document-uri(/),'/')[last()]"/></xsl:attribute> <xsl:attribute name="viewBox"><xsl:value-of select="@viewBox"/></xsl:attribute> <xsl:apply-templates select="path"/> </xsl:element> </xsl:template> <xsl:template match="path"> <xsl:element name="path"> <xsl:apply-templates select="@d,@fill"/> </xsl:element> </xsl:template> <xsl:template match="@d"> <xsl:attribute name="d"><xsl:value-of select="."/></xsl:attribute> </xsl:template> <xsl:template match="@fill"> <xsl:attribute name="fill"><xsl:value-of select="."/></xsl:attribute> </xsl:template> </xsl:stylesheet> 从命令行使用它:java net.sf.saxon.Transform -it:main -xsl:"%XSL%\svg-sprite.xsl" -o:"%OUT%\sprite.svg" 它已经非常接近工作了,但我需要获取包含的 SVG 文件的文件名,以用作 id 元素上的 <symbol> 属性。 我尝试了几种构造,使用 <xsl:for-each 而不是 <xsl:apply-templates 以及我能想到的其他所有内容,但我就是无法让它访问文件名。任何帮助将不胜感激。 我假设您对 document-uri 的尝试失败了,这是 Saxon 中的一个已知问题,因为规范的各种要求使得 Saxonica 改变了其实现;正在进行的 XPath 4 工作中存在一个放宽要求的问题,以便恢复 document-uri 的功能。 但在大多数使用情况下base-uri会这样做,尝试一下。 作为替代方案,您可以从 uri-collection 而不是 collection 开始,然后直接获得每个集合的 URI,您可以轻松提取其中的文件名,并使用 doc($uri) 处理文档,例如apply-templates。

回答 1 投票 0

2.0 版本的 XSLT 分组

想知道如何在 XSLT 中创建多个分组。以下 XML 应按 memberID、存款日期和存款类型分组。每个成员的总金额应为

回答 1 投票 0

在 pom.xml 中设置 JVM 参数的一般方法独立于所使用的插件

我有一个 Maven 项目,它通过使用 XSLT 转换在 org.codehaus.mojo.xml-maven-plugin(版本 1.0.2)的帮助下生成代码。 然而,当运行时它超出了 XPath 运算符 lim...

回答 1 投票 0

XSLT 多重分组

想知道如何在 XSLT 中创建多个分组。以下 XML 应按 memberID、存款日期和存款类型分组。每个成员的总金额应为

回答 1 投票 0

XSLT 聚合数据并以 CSV 格式输出

我正在将 XML 文件解析为新的 XML 文件,其中仅包含我需要的数据,其结构更接近我需要的最终结果。从第二个 XML 中,我运行第二个 XSLT 来获取我需要的 CSV 文件。 我的第一个 XSLT

回答 1 投票 0

JavaScript 中 XSLTProcessor.transformToFragment 的空结果

我在 JavaScript 中使用 XSLT 转换 XML 数据时遇到问题。我的设置涉及获取 XML 数据和 XSLT 样式表,该样式表嵌入在我的 HTML 中的标签内。当我尝试

回答 1 投票 0

Powershell $xslt.Transform() 以及在 xslt 中使用 Document() 函数的问题

我制作了一个 xslt 脚本,将 XML Peppol/UBL 发票转换为可以导入到我们的 ERP 系统中的 xml 格式。该脚本使用以下命令在 Powershell 中完美运行: $xsl='...

回答 1 投票 0

XSLT 使用带有 for-each 选择的变量

我对 XML 和 XSLT 非常陌生,刚刚开始一份工作,我的一个项目需要我使用它。我正在尝试使用动态变量(稍后该变量将不会被硬编码)来获取属性...

回答 3 投票 0

如何将 XSL FO 转换为 XSLT 模板

使用transformToFragment,通过传递XSLT和XML文档,我能够实现PDF 对于另一个请求,我有 XSL FO。我们可以使用XSL FO和XML文档来生成pdf吗? 请指教 你...

回答 1 投票 0

XML 转换为特定 XML 模式

我们有一个特定的要求,将XML报告输出转换为特定的格式。 下面是需要转换为所需输出格式的 XML。所有员工 ID 均应取消...

回答 1 投票 0

如何使用 XSLT 3 中的 xpath() 将元素推送到 XML 中?

我有很大的 XML 文件,需要向其中注入处理指令。处理指令的位置被列为 xpath 位置。我创建了一个小型版本的 XML 文件...

回答 1 投票 0

在多个子节点中过滤

是否可以同时在多个子节点中进行过滤? 根据下面的示例,我希望 xslt 检查“蓝色属性”值是否不存在。 我的 XML: <...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.