xslt 相关问题

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

XML 声明的大写

我面临一些 XML 大小写问题。我需要使用 XSLT 文件生成以下 xml 命名空间: 然而,在此之后

回答 1 投票 0

在 XSLT 中使用模板匹配更新多个节点值

输入XML 银行名称 测试库 输入XML <root> <Bank> <BankDetail> <Name1>BankName</Name1> <Name2>TestBank</Name2> </BankDetail> </Bank> <Item> <Item1>Text</Item1> </Item> <Item> <Item1>Text</Item1> </Item> <Item> <Item1>Text</Item1> </Item> <Item> <Item1>Text</Item1> </Item> <Item> <Item1>Text</Item1> </Item> </root> 我想用 BankItem 1、BankItem 4、BankItem 2、BankItem 5 和 BankItem 3 更新 节点值 所以输出将是 <root> <Bank> <BankDetail> <Name1>BankName</Name1> <Name2>TestBank</Name2> </BankDetail> </Bank> <Item> <Item1>BankItem - 1</Item1> </Item> <Item> <Item1>BankItem - 4</Item1> </Item> <Item> <Item1>BankItem - 2</Item1> </Item> <Item> <Item1>BankItem - 5</Item1> </Item> <Item> <Item1>BankItem - 3</Item1> </Item> </root> 我已经使用循环完成了此操作。但出于学习目的,我不想使用 For Each 循环。我想通过模板匹配来更新它。我有什么办法可以实现这个目标吗?请推荐。 我没有它工作。我尝试了几个步骤,但后来我觉得我需要一些建议。 <xsl:template match="root/Item/Item1"> <xsl:variable name="i" select="position()" /> <xsl:copy> <xsl:value-of select="Item1[$i]"/> </xsl:copy> </xsl:template> 获得所需输出的一种方法是: <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="Item1"> <xsl:variable name="i"> <xsl:number level="any"/> </xsl:variable> <xsl:copy> <xsl:text>BankItem - </xsl:text> <xsl:value-of select="substring('14253', $i, 1)"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 很难判断这是否满足您的目标,因为所需转换的逻辑尚不清楚。

回答 1 投票 0

如何在Python中使用SCH(schematron)和XSD验证XML?

我正在使用 Python 生成电子发票 XML 文件 (CII D16B)。这些文件符合 EN16931 标准 (https://github.com/ConnectingEurope/eInvoicing-EN16931)。 我需要验证生成的...

回答 1 投票 0

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