xslt 相关问题

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

XML 未按 XSLT 中的预期形成

我正在使用以下 XSLT 来形成 XML,并且代码工作正常,但我希望将此代码包装在一个条件下。 在下面的 XML 中,因为 S_HL/D_735='T' 只出现一次,这就是我

回答 1 投票 0

JSON 到 JSON 转换器

我有一个场景。 所需的输入和输出均为 JSON。 // 输入 { “旧对象”:{ 《时间》:1351160457922, “名称”:“O名称”, “数量”:100, “价格”:10 } } // 输出 { “新对象...

回答 9 投票 0

BizTalk 2020 - 将 XML 转换为数组 JSON 有效负载

我正在尝试将以下有效负载 (JSON) 发送到 REST 端点,但是当我在 BizTalk 中使用传统映射来构建 XML 架构,然后在自定义管道中使用 JSON 编码器来发送它时...

回答 1 投票 0

如何使用xslt在报表最后一页打印运行总计?

这是在一页上每 19 行分割代码我只需要获取最后一页上所有行的计数 这是在一页上每 19 行分割代码,我只需要获取最后一页上所有行的计数 <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <DATA_DS> <xsl:variable name="var_size" select="19" /> <xsl:for-each select="/DATA_DS/G_1"> <xsl:variable name="var_pos" select="position()" /> <xsl:variable name="var_mod" select="$var_pos mod($var_size)" /> <xsl:if test="$var_mod = 1"> <xsl:variable name="var_groupNum" select="($var_pos - $var_mod) div number($var_size) + 1" /> <xsl:element name="CountGroup"> <xsl:attribute name="name"> <xsl:value-of select="concat('Group',$var_groupNum)" /> </xsl:attribute> <xsl:for-each select="/DATA_DS/G_1[position() &gt; ($var_pos -1) and position() &lt; ($var_pos + $var_size)]"> <xsl:copy-of select="." /> </xsl:for-each> </xsl:if> </xsl:element> </xsl:if> </xsl:for-each> </DATA_DS> </xsl:template> </xsl:stylesheet> 我试试<xsl:if test="position()=last()"> 但还是不行your text 评论中建议使用的示例for-each-group: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all" expand-text="yes"> <xsl:output indent="yes"/> <xsl:template match="root"> <xsl:copy> <xsl:for-each-group select="item" group-adjacent="(position() - 1) idiv 19"> <page count="{position()}" is-last-page="{position() eq last()}"> <xsl:apply-templates select="current-group()"/> </page> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:mode on-no-match="shallow-copy"/> </xsl:stylesheet> 小提琴示例。 对于 XSLT 2 处理器,分组是相同的,用身份转换模板替换声明性 xsl:mode 声明

回答 1 投票 0

更新字符串 XSLT 中的特定位置

我有一个 EDI 文本文件,需要使用 XSLT 进行修改。我首先将文本文件转换为 xml,如下所示: ST^8^347 BAK^00^A^100001396^

回答 1 投票 0

在 Worpress 中使用 xsl:for-each 将 XML 存档导出到组类别域时出现问题

我需要将Wordpress生成的XML导入到数据库中。为此,我使用 XSLT 文件,但在创建类别表时遇到问题。我尝试过使用 xsl:for-each 但它不起作用。

回答 1 投票 0

如何在 XSL 属性中填充 id 及其值 <ParentElement id="abc:efg:id:hij:12345.111111.0">

如何在 XSL 属性中填充 id 及其值? 在将源 xml 转换为目标 xml 的过程中。需要有XSL文件。谁能帮助我进行 XSLT 转换? 如何在 XSL 属性中填充 id 及其值? 在将源 xml 转换为目标 xml 的过程中。需要有XSL文件。谁能帮助我进行 XSLT 转换? <xsl:template match="ParentElement/Number"> <xsl:element name="ParentElement"> <xsl:value-of select="substring(.,1,15)"/> <xsl:apply-templates/> </xsl:element> </xsl:template> 我已经尝试过上面的代码片段。 实际输出:12345.111111.0 只需使用: <xsl:template match="ParentElement/Number"> <xsl:element name="ParentElement"> <xsl:attribute name="id"> <xsl:value-of select="substring(.,1,15)"/> </xsl:attribute> <xsl:apply-templates/> </xsl:element> </xsl:template> 如果没有看到你的 XML,很难判断,但也许你想要类似的东西: <xsl:template match="ParentElement/Number"> <ParentElement id="abc:efg:id:hij:{substring(.,1,15)}"/> <xsl:apply-templates/> </ParentElement> </xsl:template>

回答 2 投票 0

使用 xslt 对列表进行排序并消除 XML 文件中的重复项 NEW

我已经问过这个问题,并且我使用了错误的示例列表,这导致了没有用的答案。然后我以为我已经找到了解决方案,但它导致了错误的结果。那我来问一下吧

回答 1 投票 0

XSLT for-each-group group-starting-with tail(current-group())

这是 Martin Honnen 的回答的后续内容。 这是我对他的建议的尝试: XSLT 小提琴链接 在电子表格形式中,数据如下所示: 在 XML 中,这是数据输入: <

回答 1 投票 0

XSLT:根据属性值和参数值选择节点

我想声明一个变量并根据属性值和参数值选择节点。 例子: <

回答 1 投票 0

如何使用 XSLT 将名称空间添加到 XML 的根元素?

我有一个输入 XML 美国 A 我的输出应该是这样的 我有一个输入 XML <Request> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> 我的输出应该是这样的 <Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://hgkl.kj.com"> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> 请让我知道如何添加多个命名空间和默认命名空间,如上面的 XML。 这是我在 XSLT 2.0 中的做法... XML 输入 <Request> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="*" priority="1"> <xsl:element name="{local-name()}" namespace="http://hgkl.kj.com"> <xsl:namespace name="xsi" select="'http://www.w3.org/2001/XMLSchema-instance'"/> <xsl:namespace name="xsd" select="'http://www.w3.org/2001/XMLSchema'"/> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> </xsl:stylesheet> XML 输出 <Request xmlns="http://hgkl.kj.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> 这里有一个 XSLT 1.0 选项,它会产生相同的输出,但要求您知道根元素的名称... <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|text()|comment()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="/Request"> <Request xmlns="http://hgkl.kj.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsl:apply-templates select="@*|node()"/> </Request> </xsl:template> <xsl:template match="*"> <xsl:element name="{local-name()}" namespace="http://hgkl.kj.com"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> </xsl:stylesheet> 这个答案显然没有优化,但会提示您如何让它在 4.2 版本的命名空间和非命名空间 XML 上工作: 这里是parseXml的body方法 JAXBContext jc = JAXBContext.newInstance(VAST.class); Unmarshaller u = jc.createUnmarshaller(); // should be optimized TransformerFactory tf = TransformerFactory.newInstance(); StringWriter sw = new StringWriter(); URL urlXslt = VastParser.class.getClassLoader().getResource("xslt/vast_4.2.xslt"); File fileXslt = new File(urlXslt.toURI()); Transformer t = tf.newTransformer(new StreamSource(new FileInputStream(fileXslt))); // transform original XML with XSLT to always add the namespace in the parsing t.transform(new StreamSource(new StringReader(xmlString)), new StreamResult(sw)); // unmarshall transformed XML JAXBElement<VAST> foo = u.unmarshal(new StreamSource(new StringReader(sw.toString())), VAST.class); return new CustomVast(foo.getValue()); src/main/resources/xslt/vast_4.2.xslt 是: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|text()|comment()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- adds the xmlns part to the VAST element --> <xsl:template match="/VAST"> <VAST xmlns="http://www.iab.com/VAST"> <xsl:apply-templates select="@*|node()"/> </VAST> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 这样,两个单元测试都适用于 4.2 部分。

回答 2 投票 0

数据转换DSL

如果这个问题太模糊,我们深表歉意。 我参与开发一个系统,主要将数据从一种格式转换为另一种格式。 这些几乎都是 XML --> XML、XML <--> JSON...

回答 1 投票 0

如何在XML中对不同级别的标签进行分组?

这里是源xml。 我们有 1 个标头级别标签。 行级别标签包含在 1 个标题级别下。 ABC公司 在 ...

回答 1 投票 0

在Python中将注释xml转换为文本

我有一个文件夹,里面有大量带有图像注释数据的xml文件。我想将xml文件转换为文本文件,以便它们可以用于YOLO模型 我已经通过

回答 3 投票 0

不带属性的Json字符串数组转换XSLT

正如标题所说,我需要一些帮助来弄清楚如何将没有属性的 JSON 数组转换为 XSL。 (1)输入: { “身体”: { “姓名”:“约翰”, “ids”...

回答 1 投票 0

XSLT 条件问题

当 QUALF 为“012”时,我需要传递 BELNR 值。如果 //E1EDK02/[QUALF=012]/BELNR 为 NULL,则复制 //E1EDK02/[QUALF=002]/BELNR 使用以下代码但出现错误 - The context i...

回答 1 投票 0

如何合并从 Apache FOP 创建的 2 个 AFP

如何将使用 apache FOP 创建的大量单独的 AFP 文件合并到单个 AFP 文件中? 也欢迎任何工具建议。

回答 1 投票 0

将计数器/序列号添加到 XSLT 中的 xml 字段

我正在使用以下代码将序列号添加到 /G_HL/S_HL 段,但不起作用。使用以下代码,我可以使用正确的序列填充 D_628,但无法在 co 中填充 D_734...

回答 1 投票 0

动态获取父节点及其值

我有一个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> 我想要的是动态获取对应父节点的hte值。我可以获得如下节点名称: <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> 但是我不知道如何获取相应的父节点及其值,例如单位元素。 我已经尝试过<xsl:value-of select="/Data/$myVariable/@unit" /></td>,但不起作用。我会不断收到错误:Unexpected token '$myVariable' during parsing of '<AnyKindTest>'。 我想你想声明一把钥匙 <xsl:key name="element-key" match="Data/Features" use="name()"/> 然后你想使用例如key('element-key', name())/@unit。 你写道: <xsl:value-of select="/Data/$myVariable/@unit" /> 我认为你的问题可能是重复的 使用 2 个参数进行 xslt 测试 您正在尝试使用 $myVariable,就好像它所保存的字符串可以以文本方式替换到您的 XPath 表达式中一样。您可能想要的是 /Data/*[name()=$myVariable]/@unit 很多人都犯过这个错误,但我不知道为什么。我不认为人们会将变量 $op 设置为“+”或“-”,然后期望 @x $op @y 执行适当的加法或减法。除非他们以前的编程经验完全是用宏语言。

回答 2 投票 0

同时复制结构和子结构

我的目标是使用 XSLT 1.0 来转换 XML 文件,以便它复制特定的节点。问题是,我需要复制也需要复制的结构的子结构。 这里

回答 1 投票 0

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