xslt 相关问题

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

如何在xsl翻译中有多个“替换”特殊字符

如何用斜杠替换字符串上的所有破折号和点?我尝试使用下面的代码。 我也尝试过使用...

回答 2 投票 0

使用XSLT输出空的HTML文本区域元素

当尝试输出空文本区域元素时,.NET XSLT 处理器会将该元素折叠为其简短形式。而不是这个: 我明白了...

回答 8 投票 0

XSLT 使用 xslt 2.0 或更高版本将纯文本文件处理为 XML

我正在与一位使用“Workday”ERP 的客户合作。该 ERP 主要处理 XML、XSLT 和 XSD 脚本,但不处理其他编程语言来将数据传入和传出 ERP。 我有一个...

回答 2 投票 0

如何在 XSLT XPath 表达式中使用变量?

如何将变量传递给 XSLT XPath。例如 如何将变量传递给 XSLT XPath。例如 <ns0:UnitCode> <xsl:value-of select="//ns1:Root/InputMessagePart_1/ ns2:ServiceMasterDetailsResponse/ ns2:ServiceMasterDetailResponse[$Counter]/ ns2:BASE_UOM/text()"/> </ns0:UnitCode> 其中 Counter 是我的 XSLT 变量。 我想将变量计数器的数值传递给上面的 XSLT XPath 表达式。 如何在 XSLT 中使用变量引用 XPath 在 select 属性中,使用 $var (如您所做的那样): <xsl:value-of select="/path/to/element[@id=$var]"/> 以下是在 XSLT 中使用变量引用的一些其他方法... 匹配图案 XSLT 1.0:不允许变量match: match属性的值包含a是错误的 VariableReference. XSLT 2.0:变量允许出现在match谓词或中 模式可能以 id FO 或关键函数调用开始, 前提是要匹配的值以文字形式提供 或对变量或参数的引用,以及键名(在 key 函数的大小写)作为字符串文字提供。这些 模式永远不会匹配根不是树中的节点 文档节点。 XSLT 2.0 匹配谓词变量示例: <xsl:variable name="globalVar" select="'value'"/> <xsl:template match="abc[. = $globalVar]"> 文字结果元素 在文字结果元素中,使用属性值模板: <img src="{$var}/image.jpg"/> 元素或属性名称 在元素或属性名称中,使用 xsl:element 或 xsl:attribute 以及属性值模板: <xsl:element name="{$var}">content</xsl:element> 或 <xsl:attribute name="{$var}">content</xsl:attribute>

回答 1 投票 0

如何将变量传递给 XSLT XPath 表达式?

如何将变量传递给 XSLT XPath。例如 如何将变量传递给 XSLT XPath。例如 <ns0:UnitCode> <xsl:value-of select="//ns1:Root/InputMessagePart_1/ ns2:ServiceMasterDetailsResponse/ ns2:ServiceMasterDetailResponse[$Counter]/ ns2:BASE_UOM/text()"/> </ns0:UnitCode> 其中 Counter 是我的 XSLT 变量。 我想将变量计数器的数值传递给上面的 XSLT XPath 表达式。 如何在 XSLT 中使用变量引用 XPath 在 select 属性中,使用 $var (如您所做的那样): <xsl:value-of select="/path/to/element[@id=$var]"/> 以下是在 XSLT 中使用变量引用的一些其他方法... 匹配图案 XSLT 1.0:不允许变量match: match属性的值包含a是错误的 VariableReference。 XSLT 2.0:变量允许出现在match谓词或中 模式可能以 id FO 或关键函数调用开始, 前提是要匹配的值以文字形式提供 或对变量或参数的引用,以及键名(在 key 函数的大小写)作为字符串文字提供。这些 模式永远不会匹配根不是树中的节点 文档节点。 XSLT 2.0 匹配谓词变量示例: <xsl:variable name="globalVar" select="'value'"/> <xsl:template match="abc[. = $globalVar]"> 文字结果元素 在文字结果元素中,使用属性值模板: <img src="{$var}/image.jpg"/> 元素或属性名称 在元素或属性名称中,使用 xsl:element 或 xsl:attribute 以及属性值模板: <xsl:element name="{$var}">content</xsl:element> 或 <xsl:attribute name="{$var}">content</xsl:attribute>

回答 1 投票 0

XSLT 将 cmd 插入 HTML 头文件

请有人帮我找出下面 XSLT 中的问题吗?我只需要将“viewport”行插入到 html 标签中,但是收到错误消息“XML 文档必须启动并且...

回答 1 投票 0

如何在生成的 HTML5 预设输出中使用 DITA 映射的“数据”元素(AEM Guides)

我对 AEM Guides/XML 文档相当陌生,目前正在尝试弄清楚如何从生成的 AEM 站点中的 DITA 映射中获取“数据”元素。 澄清一下,DITA 映射有

回答 1 投票 0

XSLT 2.0 错误检查表达式类型

XSLT 2.0 我有一封电子邮件存储在文档数据库中,在下面表示为 travEmail,我正在尝试检查小写 travEmail 是否以小写搜索查询开头,表示为...

回答 1 投票 0

我可以使用 SAXON XSLT 从文档中选择标签作为参数

这是我的代码示例。我想在转换 XML 文档时使用多个文档。因此,我将它们作为参数传递给我的 XSLT 文件。问题是我无法从中选择 XML 标签...

回答 1 投票 0

XSLT:从交叉引用中提取值

我正在尝试从与交叉引用 id 匹配的 aff 元素中提取值,但不确定使用什么 XPath 来获取特定的匹配值。 XML: 我正在尝试从与交叉引用 id 匹配的 aff 元素中提取值,但不确定使用什么 XPath 来获取特定的匹配值。 XML: <article> <contrib-group> <contrib contrib-type="author"> <name><surname>Doe</surname><given-names>Jane</given-names></name><email>email here</email><xref ref-type="aff" rid="affa">a</xref><xref ref-type="corresp" rid="cor2">*</xref> </contrib> <contrib contrib-type="author"> <name><surname>Done</surname><given-names>John</given-names></name><email>email here</email><xref ref-type="aff" rid="affb">b</xref> </contrib> <aff id="affa"><label>a</label>Department of Philosophy, <institution>University of XXX</institution>, <country>Germany</country></aff> <aff id="affb"><label>b</label>Institute of Logic, <institution>Univeristy of YYY</institution>, Virginia, <country>United States</country></aff> </contrib-group> </article> XSLT: <xsl:template match="*"> <article> <xsl:apply-templates select="//contrib-group/contrib"/> </article> </xsl:template> <xsl:template match="article/contrib-group/contrib"> <contrib> <surname><xsl:value-of select="name/surname"/></surname> <given-names><xsl:value-of select="name/given-names"/></given-names> <email><xsl:value-of select="./email"/></email> <affiliation> <xsl:if test="xref/@rid = following-sibling::aff/@id"> <xsl:value-of select="following-sibling::aff"/> </xsl:if> </affiliation> </contrib> </xsl:template> 我知道这里的<xsl:value-of>不正确 - 如何选择与@rid匹配的相应链接@id? 输出为我提供了两个贡献的隶属关系: <article> <contrib> <surname>Doe</surname> <given-names>Jane</given-names> <email>email here</email> <affiliation>aDepartment of Philosophy, University of XXX, Germany bInstitute of Logic, Ohio, United States</affiliation> </contrib> <contrib> <surname>Done</surname> <given-names>John</given-names> <email>Email here</email> <affiliation>aDepartment of Philosophy, University of XXX, Germany bInstitute of Logic, Ohio, United States</affiliation> </contrib> </article> XSLT 有一个内置的 key 机制来解决交叉引用。 XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="aff" match="aff" use="@id" /> <xsl:template match="/article"> <xsl:copy> <xsl:apply-templates select="contrib-group/contrib"/> </xsl:copy> </xsl:template> <xsl:template match="contrib"> <xsl:copy> <xsl:copy-of select="name/* | email"/> <affiliation> <xsl:value-of select="key('aff', xref[@ref-type='aff']/@rid)/(node() except label)" separator=""/> </affiliation> </xsl:copy> </xsl:template> </xsl:stylesheet> 应用于您的输入示例,这将返回: 结果 <?xml version="1.0" encoding="UTF-8"?> <article> <contrib> <surname>Doe</surname> <given-names>Jane</given-names> <email>email here</email> <affiliation>Department of Philosophy, University of XXX, Germany</affiliation> </contrib> <contrib> <surname>Done</surname> <given-names>John</given-names> <email>email here</email> <affiliation>Institute of Logic, Univeristy of YYY, Virginia, United States</affiliation> </contrib> </article>

回答 1 投票 0

将 xml 拆分为表并添加 ids

我愿意: 使用 xslt 将嵌套的 xml 转换为两个表/矩形。 (我已将表格编写为 csv,但如果它们是非嵌套 xml 就可以了。) 在两个级别任意分配 id(例如 pati...

回答 1 投票 0

XSLT 从 XML 复制依赖数据

我面临着从 xml 进行 xslt 转换的问题。 xml:节点“”在xml中重复12次,并提取依赖的业务对象

回答 1 投票 0

Saxon、XSLT:处理复杂树结构中的数千个 xml 文件

我使用一个 python 脚本来迭代复杂的树结构中的数千个 xml 文件,并执行以下 Saxon 命令: java -cp C:\saxon\SaxonHE10-6J\saxon-he-10.6.jar net.sf.saxon.

回答 1 投票 0

如何使用 XSLT 和 Xpath 对 XML 进行排序

我需要根据元素的属性对 XML 文件进行排序。 该文件与此类似 我需要根据元素的属性对 XML 文件进行排序。 该文件与此类似 <employees> <employee firstname="Mary" lastname="Poppins" age="30" hobby="Flying"/> <employee firstname="Captain" lastname="Hook" age="40" hobby="Crocodile hunting"/> <employee firstname="Thomas" lastname="Tankengine" age="102" hobby="Steam trains"/> <employee firstname="Ant" lastname="Man" age="37" hobby="hero"/> <employee firstname="Peter" lastname="Pan" age="13" hobby="Flying"/> 我需要按姓氏对员工进行排序,以便 xml 看起来像这样 <employees> <employee firstname="Captain" lastname="Hook" age="40" hobby="Crocodile hunting" /> <employee firstname="Ant" lastname="Man" age="37" hobby="hero" /> <employee firstname="Peter" lastname="Pan" age="13" hobby="Flying" /> <employee firstname="Mary" lastname="Poppins" age="30" hobby="Flying" /> <employee firstname="Thomas" lastname="Tankengine" age="102" hobby="Steam trains" /> </employees> 我尝试了各种示例并查看了 stackoverflow,但我显然错过了一些基本的东西。 这是我最新的尝试 xsl:应用模板 ” xsl:复制/ 正确的模板是 <xsl:template match="employees"> <xsl:copy> <xsl:apply-templates select="employee"> <xsl:sort select="@lastname"/> </xsl:apply-templates> </xsl:copy> </xsl:template> 然后您需要确保设置了身份转换,当前版本的 XSLT 3.0 是 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"> <xsl:output method="xml" indent="yes"/> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="employees"> <xsl:copy> <xsl:apply-templates select="employee"> <xsl:sort select="@lastname"/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet>

回答 1 投票 0

Xml 转换 - 将父属性复制到子属性

我想通过将每个父PurchaseHistory的属性Type复制到其子StoreTransaction来转换下面的xml 输入XML: 我想通过将每个父级 PurchaseHistory 的属性 Type 复制到其子级 StoreTransaction 来转换下面的 xml 输入Xml: <ArrayOfStoreTransaction CustomerID="C1"> <PurchaseHistory Type="purchase.001" Count="2"> <StoreTransaction> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> <StoreTransaction> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> </PurchaseHistory> <PurchaseHistory Type="purchase.002" Count="1"> <StoreTransaction> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> </PurchaseHistory> <PurchaseHistory Type="purchase.003" Count="2"> <StoreTransaction> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> <StoreTransaction> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> </PurchaseHistory> </ArrayOfStoreTransaction> 输出XML: <ArrayOfStoreTransaction CustomerID="C1"> <StoreTransaction Type="purchase.001"> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.001"> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.002"> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.003"> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.003"> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> </ArrayOfStoreTransaction> 所以我想要一个好的java库来以有效的方式转换我的xml,考虑到内存和执行时间,因为xml将非常大> 200mb 您只需要两个简单的 XSLT 模板规则即可: <xsl:template match="PurchaseHistory"> <xsl:apply-templates/> </xsl:template> <xsl:template match="StoreTransaction"> <StoreTransaction Type="{../@Type}"> <xsl:apply-templates/> </StoreTransaction> </xsl:template> 一个好的现代 XSLT 转换引擎应该能够毫无困难地处理 200Mb。如果它进入千兆字节范围,并且您使用支持 XSLT 3.0 流式传输的引擎,则此转换是完全可流式传输的。 不要浪费时间用 Java 进行编码。

回答 1 投票 0

重新排列层次结构 - 将所有显示为元素 para 的后续兄弟元素的 <list>(及其内容)移动到 para

我需要重新排列层次结构。将出现在 para(如下同级)之后的列表(及其内容)移动到 para 内部,同时将其余数据保留在当前位置。

回答 1 投票 0

如何在XSLT中指定小于或等于?

我正在尝试编写如下逻辑来返回数据。 ...

回答 1 投票 0

重新排列层次结构 - 将元素的后续同级元素移动到该元素末尾之前

我需要重新排列层次结构(移动出现在段落后面、段落内部的列表): 来自: ... ... 我需要重新排列层次结构(移动出现在段落后面、段落内部的列表): From: <para updated="20240205"><text> ... </text> ... </para><list type="num"> ... </list> To: <para updated="20240205"><text> ... </text> ... <list type="num"> ... </list></para> 备注: DTD 允许 para 包含列表,列表也可以包含 para 该段落后面可能有多个列表需要移动到前一个段落的末尾 我对 XSL 比较陌生,不确定如何处理这个问题,因为它们目前是兄弟姐妹 我还没有尝试任何事情,因为我不知道如何解决这个问题。 谢谢 使用例如 <xsl:template match="*[para]"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:for-each-group select="*" group-starting-with="para"> <xsl:choose> <xsl:when test="self::para"> <xsl:copy> <xsl:apply-templates select="@*, node(), tail(current-group())"/> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> 我认为 tail 是 XPath 3/XSLT 3,因此如果您确实使用 XSLT 2 处理器,请改用 subsequence(current-group(), 2)。 当然,推动一切通过apply-templates假设您已经为不想更改的节点设置了身份转换(模板),并为您想要更改的节点上的任何转换添加了模板。

回答 1 投票 0

最新的 Chrome 更新无法加载 XSLT 文档

自上次 Chrome 更新以来,当应用程序尝试加载 XSLT 文档时,它会返回空。我发现,如果您尝试返回 this.responseXML,则尝试执行 XMLHttpRequest 来加载 XLST 文件是 e...

回答 1 投票 0

XSL - 在第 n 个元素之后插入 div

我想在每个页面的第n个元素之后插入: 现在: 我想在每页的第 n 个元素之后插入 <div class="test"></div>: 现在: <iaixsl:for-each select="/shop/page/products/product"> <div class="product col-6 col-sm-4 col-md-3 pt-3 pb-md-3 mb-3 mb-sm-0 "> ... </div> </iaixsl:for-each> 现在我想放 <div class="banner"> ... </div> 在第 3 个乘积元素之后。 尝试: <xsl:if test="not(position() mod 3)"> <!-- your addition goes here --> </xsl:if>

回答 1 投票 0

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