xslt 相关问题

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

XSLT:带条件的应用模板内的数字位置

我需要在调用模板时打印位置号,但是有条件。 IE。 “position()”不合适。 调用模板时需要打印位置号,但是有条件。 IE。 “position()”不合适。 <xsl:template match="property" mode="table-group"> <xsl:variable name="property_id" select="@id" /> <xsl:if test="/shop//shop_group[@id=$group]/property_value[property_id = $property_id]/value != 0 and /shop//shop_group[@id=$group]/property_value[property_id = $property_id]/value != '' "> <tr> <td> <b><xsl:value-of select="position()" /></b> <xsl:value-of disable-output-escaping="yes" select="name"/> </td> <xsl:apply-templates select="/shop//shop_group[@id=$group]/property_value[property_id = $property_id]" mode="table-group"/> </tr> </xsl:if> </xsl:template> 请帮忙。它打破了我的大脑...... 示例 xml: <shop> <shop_group> <property_value> <value>123</value> <name>NameA</name> </property_value> <property_value> <value>0</value> <name>NameB</name> </property_value> <property_value> <value></value> <name>NameC</name> </property_value> <property_value> <value>123</value> <name>NameD</name> </property_value> <property_value> <value>321</value> <name>NameE</name> </property_value> </shop_group> </shop> 我想要得到: <tr><td>1 NameA</td>...</tr> <tr><td>2 NameD</td>...</tr> <tr><td>3 NameE</td>...</tr> 但是如果使用“position()”我得到: <tr><td>1 NameA</td>...</tr> <tr><td>4 NameD</td>...</tr> <tr><td>5 NameE</td>...</tr> 将谓词移动到处理所选 xsl:apply-templates 元素的 property 指令: <xsl:apply-templates select="//property[value != '' and value != 0]"/> 在匹配的 xsl:template 规则中,position() 现在将具有正确的值。 (请注意,示例 XSLT 中的元素名称与示例 XML 中的名称不匹配,因此可能需要调整)。

回答 1 投票 0

为什么 format-number 在 xslt 函数中不起作用?

我的代码 > > > 我的代码 <xsl:template name="sumScorest"> > <xsl:param name="pListt"/> > <xsl:param name="pAccumt" select="0"/> > <xsl:choose> > <xsl:when test="$pListt"> > <xsl:variable name="vHeadt" select="$pListt[1]"/> > <xsl:call-template name="sumScorest"> > <xsl:with-param name="pListt" select="$pListt[position() > 1]"/> > <xsl:with-param name="pAccumt" select="$pAccumt + number(substring-before(substring-after($vHeadt,'*'),'#'))"/> > </xsl:call-template> > </xsl:when> > <xsl:otherwise> > <xsl:value-of select="$pAccumt"/> > </xsl:otherwise> > </xsl:choose> > </xsl:template> 我调用代码的地方 <xsl:call-template name="sumScorest"> <xsl:with-param name="pListt" select="//n1:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:Description"/> </xsl:call-template> 输出是这样的数字(8795,885558844877),我希望小数点后有2位数字。我还希望数字以千位分隔符输出(8.795,88)。 尝试改变: <xsl:otherwise> <xsl:value-of select="$pAccumt"/> </xsl:otherwise> 至: <xsl:otherwise> <xsl:value-of select="format-number($pAccumt, '#.##0,00', 'european')"/> </xsl:otherwise>

回答 1 投票 0

xslt 仅对选定的节点进行排序

所选节点的转换和排序似乎不起作用,例如: 当低于 XSLT 时: 所选节点的转换和排序似乎不起作用,例如: 低于 XSLT 时: <?xml version="1.0" encoding="utf-8"?> <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 method="xml" omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="/" name="xsl:initial-template"> <xsl:next-match/> <xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment> </xsl:template> <xsl:template match="array"> <xsl:copy> <xsl:apply-templates select="map"> <xsl:sort select="translate(string[@key='usdt'], '-T:', '')" data-type="number" order="descending"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 应用于 XML: <map xmlns="http://www.w3.org/2005/xpath-functions"> <map key="msgHeader"> <number key="msgNumber">1</number> <string key="msgDateTime">2024-05-30T04:43:34.545</string> <string key="msgAction">mm</string> </map> <null key="refId"/> <null key="associateId"/> <string key="tt">nn</string> <string key="iac">oo</string> <null key="agm"/> <map key="am"> <string key="ac">nn</string> <string key="fn">oo</string> <null key="os"/> <number key="rias">1</number> </map> <null key="dgm"/> <map key="dm"> <string key="ac">nn</string> <string key="fn">oo</string> <null key="os"/> <number key="rias">1</number> </map> <array key="p"> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T04:43:34</string> </map> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T10:55:05</string> </map> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T03:45:06</string> </map> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T18:33:25</string> </map> </array> <array key="t"> <map> <string key="dps">D1</string> <string key="sddt">2024-05-30T08:43:34</string> </map> <map> <string key="dps">D1</string> <string key="sddt">2024-05-30T11:55:05</string> </map> <map> <string key="dps">D1</string> <string key="sddt">2024-05-30T14:45:06</string> </map> <map> <string key="dps">D1</string> <string key="sddt">2024-05-30T19:33:25</string> </map> </array> </map> 结果 XML 应按如下方式排序: <array key="p"> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T03:45:06</string> </map> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T04:43:34</string> </map> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T10:55:05</string> </map> <map> <string key="s">D1</string> <string key="usdt">2024-05-30T18:33:25</string> </map> </array> 不知何故,输出未排序,知道为什么排序在这种情况下不起作用吗? 链接到小提琴 您遇到命名空间问题。您需要在样式表中添加 xpath-default-namespace="http://www.w3.org/2005/xpath-functions" 声明,否则 <xsl:template match="array"> 将不会被应用。 您可以将代码简化为: <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xpath-default-namespace="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="#all"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="array"> <xsl:copy> <xsl:apply-templates select="map"> <xsl:sort select="xs:dateTime(string[@key='usdt'])" order="descending"/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet>

回答 1 投票 0

json-doc 在浏览器中打开时返回样式表中的空白页面

当我在 XSLT 中的浏览器中使用 json-doc 来读取 XML 并生成 HTML 时,浏览器(Firefox、Chrome 和 Safari)返回空白页面。 XSLT的部分是这样的: 当我在 XSLT 内的浏览器中使用 json-doc 来读取 XML 并生成 HTML 时,浏览器(Firefox、Chrome 和 Safari)返回空白页面。 XSLT的部分是这样的: <td> <xsl:variable name="activityLink" select="json-doc(concat('https://deims.org/api/activities/', substring-after(//cs:campaign, 'https://deims.org/activity/')))"/> <a href="{//cs:campaign}" target="_blank"> <xsl:value-of select="$activityLink?title"/> </a> </td> 关于cs:campaign的部分是: <cs:campaign>https://deims.org/activity/50d7a52d-e384-4ed4-9976-5bf9c8302843</cs:campaign> 我看一下这个标题: <td>Lago di Garda - Italy ...</td> 使用 SaxonJS 2 这有效: const xml = `<sample>https://deims.org/api/activities/50d7a52d-e384-4ed4-9976-5bf9c8302843</sample>`; const xslt = `<?xml version="1.0" encoding="utf-8"?> <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:template match="sample"> <xsl:copy>{json-doc(.)?title}</xsl:copy> </xsl:template> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="/" name="xsl:initial-template"> <xsl:next-match/> <xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment> </xsl:template> </xsl:stylesheet> `; const result = SaxonJS.XPath.evaluate(` transform(map { 'stylesheet-text' : $xslt, 'source-node' : parse-xml($xml), 'delivery-format' : 'serialized' })?output`, null, { params : { xml : xml, xslt : xslt } } ); console.log(result); <script src="https://martin-honnen.github.io/SaxonJS-2.6/SaxonJS2.js"></script>

回答 1 投票 0

每个文本的 XSL 都以变量中的选择开头

我的输入中有以下 XML: RH03051CDSIA280524CM1490301951171 610000001 93001 ...

回答 1 投票 0

使用 Saxon 流删除 XSLT 中的重复对象

我需要帮助从提要中删除重复的项目并映射第一个对象。为此,我使用 xsl:for-each-group 按 id 对对象进行分组并使用它。 它适用于小型 XML 但当...

回答 1 投票 0

注释框与文本对齐

我正在使用XLST转换为html,有一个部分我希望评论框与文本在同一行对齐。我附上了一张我的目标的图片......

回答 1 投票 0

如何针对多种条件应用xsl模板?

我尝试根据多种条件应用 xsl 模板,例如: 应用相同的模板,如果 节点的子节点存在或 节点存在 例如: 我正在尝试基于多种条件应用 xsl 模板,例如: 应用相同的模板,如果 节点的子节点存在或 节点存在 例如: <root> <data> <test>VVV</test> <item>AAA</item> <item>BBB</item> </data> </root> 我需要在以下两种情况之一下应用相同的模板: 如果数据/项目存在或 如果数据存在 解析根目录后,尝试以下操作: 预期结果: 如果数据/项目存在,则在该元素级别调用模板,否则,如果数据存在,则调用相同的模板。 但就我而言,只要存在数据/项目,它就会应用模板两次:首先在数据级别,然后在数据/项目级别,这与预期不符。有人可以帮忙吗? 您可以使用例如<xsl:apply-templates select="data/item | data[not(item)]" mode="testMode" />但显然很难判断您是否有正确的模板来处理 data 以及 item 元素,因为您没有显示您正在谈论的模板。

回答 1 投票 0

在 Linux 上通过 xsltproc 将 XML 块插入到 .xml 文件中

我有这个原始的.xml 文件树: 嗨 我有这个原始的.xml 文件树: <?xml version="1.0"?> <root xmlns="http://www.tibco.com/xmlns/"> <element1> <name>Hi</name> </element1> <element2> <name>Beer</name> </element2> <element2> <name>Balloon</name> <element2_1> <name>John</name> </element2_1> </element2> </root> 我正在尝试在 element2 父级下添加 element2_2。我尝试基于“xsl:元素匹配”进行插入(xslt 样式表作为脚本的一部分),如下所示: cat <<EOT > insert.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="root/element2[@name='Balloon']"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> <xsl:element name="element2_2"> <xsl:attribute name="name">Edward</xsl:attribute> </xsl:element> </xsl:template> </xsl:stylesheet> EOT 然后使用xsltproc根据Linux上的特定位置(标签和元素)将insert.xsl插入到original.xml中: xsltproc insert.xsl original.xml > ./updated.xml 不幸的是什么也没发生。我发现的唯一工作是将匹配模式更改为根(“/*”)并将 xsl:element 编辑为实际的 .xml 元素,这导致在 root 之后连接元素(不是有用的)。 所需输出: <root> <element1> <name>Hi</name> </element1> <element2> <name>Beer</name> </element2> <element2> <name>Balloon</name> <element2_1> <name>John</name> </element2_1> <element2_2> <name>Edward</name> </element2_2> </element2> </root> 假设环境之间没有差异。 @name 选择 XML 中没有的属性,所以我怀疑您只是想要 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="root/element2[name='Balloon']"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> <element2_2> <name>Edward</name> </element2_2> </xsl:copy> </xsl:template> </xsl:stylesheet> 使用客户端 JavaScript 进行演示(在基于 Chromium 的浏览器中,libxslt 与 xsltproc 中的处理器相同): const xmlSource = `<root> <element1> <name>Hi</name> </element1> <element2> <name>Beer</name> </element2> <element2> <name>Balloon</name> <element2_1> <name>John</name> </element2_1> </element2> </root>`; const domParser = new DOMParser(); const xmlDoc = domParser.parseFromString(xmlSource, 'application/xml'); const xsltSource = `<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="root/element2[name='Balloon']"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> <element2_2> <name>Edward</name> </element2_2> </xsl:copy> </xsl:template> </xsl:stylesheet>`; const xsltDoc = domParser.parseFromString(xsltSource, 'application/xml'); const xsltProc = new XSLTProcessor(); xsltProc.importStylesheet(xsltDoc); const resultDoc = xsltProc.transformToDocument(xmlDoc); //console.log(resultDoc); console.log(new XMLSerializer().serializeToString(resultDoc));

回答 1 投票 0

通过 XSLT 有条件地连接 XML 节点值

我对 StackOverflow 非常陌生,我已经阅读了很多 XSLT 问题,但我正在努力寻找我面临的问题的答案。 我目前正在使用两种不同的 XML ...

回答 1 投票 0

合并两个单词列表不适用于位置功能

我一直在尝试通过将两个不同的单词列表混合在一起来获取字典,但是当我通过 Saxon 运行它时,它只在每一行重复 wordlist2 中的单词#1。看起来 Position() 保留了

回答 1 投票 0

XML 声明中“encoding”值的大写

我面临一些 XML 大小写问题。我需要使用 XSLT 文件生成以下 XML 声明: 然而,之后...

回答 1 投票 0

XSLT 错误:提供给 xsl:evaluate 的 XPath 表达式中出现静态错误:XPath 表达式中未声明变量

我尝试使用特定标签中的值作为变量名。但是,在转换 xml 时,系统会在 XPath 表达式中给出未声明的变量异常。 我的 Xml 文件是 我尝试使用特定标签中的值作为变量名。但是在转换 xml 时系统给出了 XPath 表达式中未声明的变量异常。 我的 Xml 文件是 <request> <entityType>individual</entityType> </request> Xslt 文件是 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math" version="3.0"> <xsl:param name="individual" static="yes" as="xs:string" select="'1'"/> <xsl:param name="legal" static="yes" as="xs:string" select="'2'"/> <xsl:template match="/*"> <xsl:param name="entity" as="xs:string" select="concat('$',entityType)"/> <xsl:variable name="input" as="xs:string"> <xsl:evaluate xpath="$entity"/> </xsl:variable> <HTML><TITLE><xsl:value-of select="$input"/></TITLE></HTML> </xsl:template> </xsl:stylesheet> 我期望结果为 <HTML><TITLE>1</TITLE></HTML> 但是我收到“提供给 xsl:evaluate 的 XPath 表达式中出现静态错误:XPath 表达式中未声明的变量”消息。 如果您阅读https://www.w3.org/TR/xslt-30/#dynamic-xpath,那么您会发现它清楚地指出“在xsl:variable或xsl:param元素中的样式表中声明的变量不是在目标表达式的范围内。”。您必须在 xsl:with-param 内使用 xsl:evaluate 和/或 with-params 上的 xsl:evaluate 来声明所需的参数。 <xsl:evaluate xpath="$entity" with-params="map{ QName('', 'individual') : $individual }"/>

回答 1 投票 0

XSLT 中的 for 循环缺少什么?

我尝试从下面给定的 XML 编写 XSLT,但没有得到正确的输出。 我尝试从下面给定的 XML 编写 XSLT,但没有得到正确的输出。 <?xml version="1.0" encoding="UTF-8"?> <n0:EPCISDocument xmlns:n0="urn:epcglobal:epcis:xsd:1" schemaVersion="1.2" creationDate="2024-03-12T14:28:47.272374Z"> <EPCISBody> <EventList> <AggregationEvent> <parentID>urn:epc:id:sscc:0361958.1000010007</parentID> <childEPCs> <epc>urn:epc:id:sgtin:539150714.0666.354159881283</epc> <epc>urn:epc:id:sgtin:539150714.0666.438941790942</epc> </childEPCs> </AggregationEvent> <AggregationEvent> <parentID>urn:epc:id:sscc:0361958.1000010008</parentID> <childEPCs> <epc>urn:epc:id:sgtin:539150714.0666.497811017409</epc> <epc>urn:epc:id:sgtin:539150714.0666.600301574096</epc> </childEPCs> </AggregationEvent> <AggregationEvent> <parentID>urn:epc:id:sscc:0361958.0001052872</parentID> <childEPCs> <epc>urn:epc:id:sscc:0361958.1000010007</epc> <epc>urn:epc:id:sscc:0361958.1000010008</epc> </childEPCs> </AggregationEvent> </EventList> </EPCISBody> </n0:EPCISDocument> ................................................ ...................................................... ...................... ------------------------------------------------- ---------------------------- 实际产量- <?xml version="1.0" encoding="UTF-8"?> <tns:despatchAdvice xmlns:tns="urn:ean.ucc:deliver:2"> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.1000010007</levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sscc:0361958.1000010007</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.1000010007</levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sscc:0361958.1000010008</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.1000010007</levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sscc:0361958.1000010007</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.1000010007</levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sscc:0361958.1000010008</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.1000010007</levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sscc:0361958.1000010007</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.1000010007</levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sscc:0361958.1000010008</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> </tns:despatchAdvice> 预期产出- <?xml version="1.0" encoding="UTF-8"?> <ns3:despatchAdvice xmlns:ns3="urn:ean.ucc:deliver:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.0001052872</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification>urn:epc:id:sscc:0361958.0001052872</levelIdentification> </levelId> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010007</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <parentLevelId> <levelIdentification>urn:epc:id:sscc:0361958.0001052872</levelIdentification> </parentLevelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sgtin:539150714.0666.354159881283</serialNumber> </listForEachItem> <listForEachItem> <serialNumber>urn:epc:id:sgtin:539150714.0666.438941790942</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode>urn:epc:id:sscc:0361958.1000010008</serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <parentLevelId> <levelIdentification>urn:epc:id:sscc:0361958.0001052872</levelIdentification> </parentLevelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber>urn:epc:id:sgtin:539150714.0666.497811017409</serialNumber> </listForEachItem> <listForEachItem> <serialNumber>urn:epc:id:sgtin:539150714.0666.600301574096</serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> </ns3:despatchAdvice> 下面是我尝试过的 XSLT 代码,但没有给出预期的输出。 <xsl:template match="/"> <tns:despatchAdvice> <xsl:for-each select="/ns0:EPCISDocument/EPCISBody/EventList/AggregationEvent"> <xsl:for-each select="/ns0:EPCISDocument/EPCISBody/EventList/AggregationEvent[contains(childEPCs/epc, 'sscc')]/childEPCs/epc"> <despatchAdviceLogisticUnitLineItem> <logisticUnitIdentification> <serialShipmentContainerCode> <serialShippingContainerCode> <xsl:value-of select="/ns0:EPCISDocument/EPCISBody/EventList/AggregationEvent/parentID"/> </serialShippingContainerCode> </serialShipmentContainerCode> </logisticUnitIdentification> <levelId> <levelIdentification> <xsl:value-of select="/ns0:EPCISDocument/EPCISBody/EventList/AggregationEvent/parentID"/> </levelIdentification> </levelId> <despatchAdviceItemContainmentLineItem> <listForEachItem> <serialNumber> <xsl:value-of select="."/> </serialNumber> </listForEachItem> </despatchAdviceItemContainmentLineItem> </despatchAdviceLogisticUnitLineItem> </xsl:for-each> </xsl:for-each> </tns:despatchAdvice> </xsl:template> 有人可以建议我编写的 XSLT 代码中缺少什么吗?请建议如何从 XSLT 获得正确的输出。这是场景- 在输入文件中我们有三个AggregationEvent,循环应该跟随三次。 在输入文件的最后一个 AggregationEvent 中,我们有两个子 epc。在第一个循环中,应为serialShippingContainerCode 和levelIdentification 显示parentID 的值。在第二个循环中,parentID 的值应出现在parentLevelId 下的levelIdentification 中,并且第一个AggregationEvent 的parentID 应出现在serialShipmentContainerCode 下的serialShippingContainerCode 中。在第二个循环中,只有第一个 AggregationEvent 的 childEPCs/epc 应填充其序列号值。在第三个循环中,parentID 的值应出现在parentLevelId 下的levelIdentification 中,并且第一个AggregationEvent 的parentID 应出现在serialShipmentContainerCode 下的serialShippingContainerCode 中。在第三个循环中,只有第二个 AggregationEvent 的 childEPC/epc 才应填充其序列号值。 xsl:for-each 指令会更改上下文。在 for-each 中,您应该使用相对路径,而不是绝对路径。 你写 for each /a/b for each /a/b/c value of /a/b/c/d 应该是 for each /a/b for each c value of d

回答 1 投票 0

添加或替换节点和属性通过xsl转换Xml,并通过转换xsl将转换后的xml呈现在html表格中

我必须将 xml 文件转换为 html,添加(或替换) xml文件的特定节点和属性,通过代码 xsl。问题是: (a) 渲染整个替换节点

回答 1 投票 0

遇到XML中的空标签时添加空格

我使用 Apache FOP 创建 PDF。 我的 XML 的一部分如下所示。基本上,我试图将标签的全部内容按原样放入 PDF 中,但我在这里遇到了一些挑战。 我想要...

回答 1 投票 0

回答 1 投票 0

正则表达式获取+

我有以下文件内容 NAD+DP+++Test GmbH & Co. KG:Filiale Test:Test+Groß Test Straße 96-98+Berlin++13452+DE' 我想获取 + 段之间的所有字符串。即使他们是...

回答 1 投票 0

替换空元素

作为我工作流程的一部分,我收到 xml 文件,有时特定元素为空,这会导致系统出现问题,这是一个示例输入文件: 作为我工作流程的一部分,我收到 xml 文件,有时特定元素为空,这会导致系统出现问题,这是一个示例输入文件: <?xml version="1.0" encoding="UTF-8"?> <CompositionPlaylist xmlns="http://www.xml.com/20040511#"> <Id>urn:uuid:129de837-6eed-40d4-a635-db58380dfd9e</Id> <AnnotationText>Title</AnnotationText> <IssueDate>2014-09-22T19:18:56.001+01:00</IssueDate> <Issuer>issuer</Issuer> <Creator>Creator Name</Creator> <ContentTitleText>Content Title</ContentTitleText> <ContentKind>feature</ContentKind> <ContentVersion> <Id>urn:uuid:e52a4259-ecad-4630-be51-cf13f95d8b82</Id> <LabelText>Title of the media</LabelText> </ContentVersion> <RatingList/> <ReelList> <Reel> <Id>urn:uuid:1b840b2b-7526-4597-ae2d-81994f8e9867</Id> <AnnotationText>FeG_r1_new</AnnotationText> <AssetList> <MainPicture> <Id>urn:uuid:e6ac03bd-65a5-4dab-bb24-682c6b5bf61a</Id> <EditRate>24 1</EditRate> <IntrinsicDuration>25965</IntrinsicDuration> <EntryPoint>0</EntryPoint> <Duration>25965</Duration> <Hash>3VTtxrGsVs1AsE4JXU12wdF/U0o=</Hash> <FrameRate>24 1</FrameRate> <ScreenAspectRatio>1.77</ScreenAspectRatio> </MainPicture> <MainSound> <Id>urn:uuid:1202f14c-13ce-4585-8a3f-fd489b6c6bac</Id> <EditRate>24 1</EditRate> <IntrinsicDuration>25990</IntrinsicDuration> <EntryPoint>0</EntryPoint> <Duration>25965</Duration> <Hash>cU4riXDJwfsQ9rL7tkd0c8nZgWw=</Hash> <Language>und</Language> </MainSound> </AssetList> </Reel> 有时元素“ContentVersion”是空的,如下所示: <ContentVersion> <LabelText/> </ContentVersion 用“虚拟”元素替换该元素就可以了,就像这样 <ContentVersion> <Id>urn:uuid:11111111-1111-1111-1111-111111111111</Id> <LabelText>DUMMY</LabelText> </ContentVersion> 采取的步骤 尝试过 XSLT 转换,但找不到用 cild 替换完整元素的方法 当您说 ContentVersion 不能为空时,我不确定您到底想要测试什么,但是例如,如果您的测试是它必须有一个非空 LabelText,那么您的 XSLT 转换就可以了 <xsl:template match="ContentVersion[not(LabelText) or LabelText = '']"> <ContentVersion> <Id>urn:uuid:11111111-1111-1111-1111-111111111111</Id> <LabelText>DUMMY</LabelText> </ContentVersion> </xsl:template> 如果您对“空”的定义不同,请根据您的口味调整谓词。

回答 1 投票 0

使用 XSL 提取 XML 文件的子集

我有这个XML文件: 错误代码 留言 ...

回答 4 投票 0

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