xslt-2.0 相关问题

将此标记用于特定于XSL Transformations版本2.0的问题,而不是其他版本。

XSLT - 将单个属性分离为具有属性的多个元素

我有一些源 XML,其中包含对一个属性内多个值的交叉引用。我需要将它们分成具有属性值的自己不同的元素。 输入 XML: B... 我有一些源 XML,其中包含对一个属性内多个值的交叉引用。我需要将它们分成具有属性值的自己不同的元素。 输入XML: <p>Blah blah blah <xref ref-type="bibr" rid="ref004 ref005 ref006 ref007">4&#x2013;7</xref>.</p> 所需的输出 XML: <p>Blah blah blah <xref ref-type="bibr" rid="ref004">4</xref><xref ref-type="bibr" rid="ref005"/><xref ref-type="bibr" rid="ref006"/>&#x2013;<xref ref-type="bibr" rid="ref007">7</xref>.</p> 注意中间的 2 个交叉引用变成了空元素。 我有以下 XSLT,但它没有给我正确的输出 - 它将属性值作为元素内容插入。 <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="xref"> <xsl:variable name="rid" select="@rid"/> <xsl:choose> <xsl:when test="contains($rid, ' ')"> <!-- Multiple references --> <xsl:variable name="refs" select="tokenize($rid, ' ')"/> <xsl:for-each select="$refs"> <xsl:if test="position() > 1"> <xsl:text> </xsl:text> </xsl:if> <xsl:variable name="refNum" select="substring-after(., 'ref')"/> <xsl:element name="xref"> <xsl:attribute name="ref-type">bibr</xsl:attribute> <xsl:attribute name="rid"> <xsl:value-of select="concat('ref', $refNum)"/> </xsl:attribute> <xsl:value-of select="."/> </xsl:element> </xsl:for-each> </xsl:when> <xsl:otherwise> <!-- Single reference --> <xsl:element name="xref"> <xsl:attribute name="ref-type">bibr</xsl:attribute> <xsl:attribute name="rid"> <xsl:value-of select="$rid"/> </xsl:attribute> <xsl:value-of select="."/> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template> 我想我通过使用得到了预期的结果: <xsl:stylesheet version="2.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="xref[contains(@rid, ' ')]"> <xsl:variable name="ref" select="text()"/> <xsl:for-each select="tokenize(@rid, ' ')"> <xsl:choose> <xsl:when test="position()=1"> <xref ref-type="bibr" rid="{.}"> <xsl:value-of select="substring-before($ref, '&#x2013;')"/> </xref> </xsl:when> <xsl:when test="position()=last()"> <xsl:text>&#x2013;</xsl:text> <xref ref-type="bibr" rid="{.}"> <xsl:value-of select="substring-after($ref, '&#x2013;')"/> </xref> </xsl:when> <xsl:otherwise> <xsl:text> </xsl:text> <xref ref-type="bibr" rid="{.}"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet> 但这主要是基于根据您的单个示例猜测规则是什么......

回答 1 投票 0

如何根据子节点的条件获取父节点?

我有以下xml: 数字 ...

回答 1 投票 0

将 xml 转换保存在新的 xml 文件中

嘿嘿! 我有一个 xslt 文件来转换我的 xml,它运行得很好:) 但我只在氧气终端中得到结果,而不是在单独的文件中。 我试过: 嘿! 我有一个 xslt 文件来转换我的 xml,它运行得很好:) 但我只能在氧气终端中获得结果,而不是在单独的文件中。 我尝试过: <xsl:stylesheet xmlns="http://www.tei-c.org/ns/1.0" xmlns:telota="http://www.telota.de" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xpath-default-namespace="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="xs" version="2.0"> <xsl:result-document href="new_badius.xml"/> 这给了我错误:“元素 xsl:result-document 不得直接出现在 xsl:stylesheet 中” 尝试了一些层次结构的变化: <xsl:template match="node()|@*"> <xsl:copy> <xsl:result-document href="new_file.xml"/> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> 或 <xsl:template match="node()|@*"> <xsl:result-document href="new_file.xml"/> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> 这给了我错误只能创建一个 new_file.xml (它是空的) 我应该把<xsl:result-document href="new_file.xml"/>放在哪里,或者有更好的方法将我的结果保存为.xml吗? xsl:result-document属于模板,哪个模板显然取决于您的XML输入结构、样式表结构以及结果文档的数量和想要的内容。 另请注意,oXygen 允许您配置一个转换场景,您可以在其中定义将主要结果写入到您可以定义名称的文件中,请参阅 https://www.oxygenxml.com/doc/versions/26.1/ ug-editor/topics/the-output-tab.html.

回答 1 投票 0

如何按照计划代码的顺序获取每个元素值

我需要表行应按照代码值的顺序获取 输入 xml 我有: 20000 我需要表行应按照代码值的顺序获取 输入我有的xml: <Group> <Maps> <Map> <Code>20000</Code> </Map> <Map> <Code>30000</Code> </Map> </Maps> <Details> <Detail> <Code>30000</Code> <Description>Benefit</Description> </Detail> <Detail> <Code>20000</Code> <Description>Non-Benefit</Description> </Detail> </Details> </Group> XSL 我已经使用变量尝试了以下操作: <xsl:template match="Group"> <xsl:variable name="MapCode" select="Maps/Map/Code"/> <row> <entry>Code</entry> <xsl:for-each select="Maps/Map"> <entry> <p> <xsl:value-of select="Code"/> </p> </entry> </xsl:for-each> </row> <row> <entry>Level</entry> <xsl:for-each select="Details/Detail[Code=$MapCode]"> <entry> <p> <xsl:value-of select="Description"/> </p> </entry> </xsl:for-each> </row> </xsl:template> 我得到的实际输出: <row> <entry>Code</entry> <entry> <p>20000</p> </entry> <entry> <p>30000</p> </entry> </row> <row> <entry>Level</entry> <entry> <p>Benefit</p> </entry> <entry> <p>Non-Benefit</p> </entry> </row> 预期输出应该是: <row> <entry>Code</entry> <entry> <p>20000</p> </entry> <entry> <p>30000</p> </entry> </row> <row> <entry>Level</entry> <entry> <p>Non-Benefit</p> </entry> <entry> <p>Benefit</p> </entry> </row> 根据 Code 订单匹配,应选择 Description 值。我将变量用于 Code 匹配。但它仍然错误地选择了 Description 值。所以描述应该按照代码顺序选择。 我猜你想做类似的事情: 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:key name="detail-by-code" match="Detail" use="Code" /> <xsl:template match="/Group"> <xsl:variable name="headings" select="Maps/Map" /> <table> <!-- header --> <row> <xsl:for-each select="$headings"> <entry> <p> <xsl:value-of select="Code"/> </p> </entry> </xsl:for-each> </row> <!-- data --> <xsl:for-each select="Details"> <xsl:variable name="current-row" select="." /> <row> <xsl:for-each select="$headings"> <entry> <p> <xsl:value-of select="key('detail-by-code', Code, $current-row)"/> </p> </entry> </xsl:for-each> </row> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>

回答 1 投票 0

XML 节点值的 OR 条件

我需要检查XML节点的值。 但为什么这不起作用呢? 我需要检查XML节点的值。 但为什么这不起作用? <xsl:if test="(applicationData/remittingAccount/paymentMethodCode != 'ABC' or applicationData/remittingAccount/paymentMethodCode != 'XYZ')"> 我也尝试过这个 <xsl:if test="(applicationData/remittingAccount/paymentMethodCode != 'ABC') or (applicationData/remittingAccount/paymentMethodCode != 'XYZ')"> 还有这个 <xsl:if test="applicationData/remittingAccount/paymentMethodCode != 'ABC' or applicationData/remittingAccount/paymentMethodCode != 'XYZ'"> 请帮忙! 您还没有解释您想要检查的内容,但是那些在 XPath 通用比较运算符的语义上苦苦挣扎的人可能想要检查,例如not(applicationData/remittingAccount/paymentMethodCode = ('ABC', 'XYZ')) 而不是你的尝试。仅当 applicationData/remittingAccount/paymentMethodCode 都不等于 ABC 或 XYZ 时,该检查才为真。 测试: test="node != 'ABC' or node != 'XYZ'" 当节点不存在时,将返回 false only。 在所有其他情况下,即使只有一个节点,测试也始终为 true - 因为节点的字符串值不能同时为“ABC”和“XYZ”,因此至少其中一个语句将说实话。 您可能正在寻找 test="not(node = 'ABC' or node = 'XYZ')" 如果没有节点具有这些字符串值,则为真。

回答 2 投票 0

具有多个 LineItems 的 Xml 到 Json

我正在尝试将 xml 转换为 json,但在 xml 到 json 转换期间未形成多个行项目。我们总是在 xml 消息中包含单个或多个 Lineitem,其名称与“vpoItemLi...

回答 1 投票 0

为什么这个属性选择没有返回值?

我需要在 XSLT 中使用某种字典,以便在给定一个键时我可以取回一个值。我知道有更正式的方法可以做到这一点,但它们与我的问题无关。 当给定

回答 1 投票 0

从不同的子节点 XSLT 填充递归元素

我正在尝试向下查看 XML 文档中的某个级别,选择不同的值并为每个不同的值填充新元素。例如。获取输入 xml <

回答 1 投票 0

XML/XSLT:以不同的方式设计类似的标记场景

我有两种情况,在 XML 中的 标签内使用 标签: 标签包含纯文本和偶尔的 标签(典型用途): 这是一句话... 我有两种情况,在 XML 中的 <b> 标签内使用 <p> 标签: <p>标签包含纯文本和偶尔的<b>标签(典型用途): <p>This is a sentence with a <b>bold</b> word.</p> <p>标签仅包含<b>标签: <p><b>This is a subsection title</b></p> 我可以仅在场景 2 中使用 XSLT 2.0 更改 <b> 标签的字体大小吗? 我知道我可以轻松地使用 CSS 的 outputclass 属性和样式,但长话短说,这不足以满足我的需求。 匹配 p[not(text())]/b 的模板将仅处理那些没有任何同级文本节点的 b 元素。 如果没有您尝试的更多内容,最简洁的挑战可能就是添加样式属性。因此,在这里我只会为您提供可能用于样式属性的片段以及不选择具有非空白同级节点的方法。 <xsl:attribute name="style"> <xsl:value-of select="'font-size:3em;'"/> </xsl:attribute> 至于如何选择,如果没有更多的 XML (HTML),您正尝试更新或修复未在 XSLT 中发布的内容,则不容易识别。 <xsl:template match="p/b"> <xsl:attribute name="style" select="concat('font-size: ', '3em', 'em;')"/> </xsl:template> preceding-sibling::node()[not(self::text()[normalize-space()='')][1][self::text()] 应该足以检查第一个不是空白文本节点的前同级节点是文本节点 诸如新行和缩进之类的空白是它们自己的文本节点,因此您可能需要将类似的内容添加到样式表中。 <xsl:strip-space elements="*"/>

回答 2 投票 0

XSLT-2 xsl:if 带有处理指令

嘿嘿! 我想查询处理指令中是否出现“:”,然后才执行某些操作。 在我只匹配 oxy_comment_start 之前,我想对其进行改进。 在这种情况下,它...

回答 1 投票 0

XSLT 2.0 转换:按值和元素对节点进行分组

尝试转换 xml 并按 xslt 2.0 中的值和元素对节点进行分组 我有一个输入 xml 如下: ...

回答 1 投票 0

如何将 XSL 文件包含到另一个文件中?

我使用 XSLT 版本 2.0,我想在另一个文件 home.xsl 中包含头模板 head.xsl。 主页.xsl: 我使用 XSLT 版本 2.0,我想在另一个文件中包含一个头模板 head.xsl home.xsl。 home.xsl: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output method="html" indent="yes"/> <xsl:template match="/"> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <title/> </head> <body> <div id="main"> <div id="content"> <xsl:call-template name="home-in"/> </div> </div> </body> </html> </xsl:template> </xsl:stylesheet> head.xsl: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output method="html" indent="yes"/> <xsl:template match="/"> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <title/> </head> <body> <div id="container"> <div id="header"> <div id="menu"> <ul> <li><a href="#" class="active">Home</a></li> <li><a href="#">about</a></li> </ul> </div> </div> </div> </body> </html> </xsl:template> </xsl:stylesheet> 如何将我的 head.xsl 文件包含到 home.xsl 中? 您可以使用 <xsl:include> 包含其他文件 您的home.xsl文件将如下所示 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output method="html" indent="yes"/> <xsl:include href="head.xsl"/> <xsl:template match="/"> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"/> <title/> </head> <body> <div id="main"> <div id="content"> <xsl:call-template name="home-in"/> </div> </div> </body> </html> </xsl:template> </xsl:stylesheet> 更多详情 XSLT 处理器将简单地将指令替换为 href 属性中命名的样式表的内容。请注意,包含的样式表模板将具有与包含的样式表相同的默认优先级和导入优先级。 不要将 xsl:include 与 xsl:import 混淆,两者类似,只是导入样式表中的指令可以被导入样式表和任何包含的样式表中的指令覆盖。换句话说,导入样式表中元素的导入优先级始终低于导入样式表的导入优先级。 由于使用xsl:include与复制文件中的代码相同,因此在使用命名模板时请确保没有重复的模板名称。 这里是来自w3 documentation的粘贴 多次包含样式表可能会导致错误,因为 重复的定义。当以下情况时,这种多重包含不太明显: 它们是间接的。例如,如果样式表 B 包含样式表 A, 样式表 C 包含样式表 A,样式表 D 包含两者 样式表 B 和样式表 C,则 A 将被 D 间接包含 两次。如果 B、C 和 D 全部用作独立样式表,则 通过分离 B 中除 将 A 包含到单独的样式表 B' 中并将 B 更改为包含 只是包含 B' 和 A,与 C 类似,然后将 D 更改为 包括 A、B'、C'。 请注意,xsl:include和xsl:import元素都只允许作为顶级元素。

回答 1 投票 0

按孤儿元素(或未知出身的元素)的顺序获取下一个兄弟姐妹

考虑(手写代码,如有意外敬请谅解) <...

回答 1 投票 0

根据通道编号顺序,应选择值

我需要根据输入 xml 中的通道编号顺序选择值 1 生活 <

回答 1 投票 0

需要从不同费率中获取金额

我需要使用相同的带值从多个费率中获取特定金额 输入 xml 我有: 2000

回答 1 投票 0

需要使用<xsl:each>

我需要使用 从多个 PlanDetail 中获取描述值 1 ...

回答 1 投票 0

使用 XSLT 显示两个不同日期之间的所有日期

我需要一个适用于 XSLT 2.0 的正确逻辑,用于显示给定两个不同日期之间的所有日期。例如如果 开始日期:2022年10月1日(年-月-日) 结束日期:2023-04-01 我需要显示结果...

回答 1 投票 0

XSLT 将平面 xml 结构转变为分层结构

我需要一个 xslt,它可以采用平面 xml 并将其转换为分层结构。 来源是这样的: 我需要一个 xslt,它可以采用平面 xml 并将其转换为分层结构。 来源是这样的: <?xml version="1.0" encoding="UTF-8"?> <ns0:FlatInfo xmlns:ns0="http://mynamespace.com"> <Header> <OrderNo>100</OrderNo> </Header> <Item> <ItemNo>1</ItemNo> <Product>Slime</Product> <Quantity>2</Quantity> </Item> <Item> <ItemNo>2</ItemNo> <Product>Gunge</Product> <Quantity>4</Quantity> </Item> <Header> <OrderNo>102</OrderNo> </Header> <Item> <ItemNo>1</ItemNo> <Product>Sludge</Product> <Quantity>55</Quantity> </Item> </ns0:FlatInfo> 这需要变成: <?xml version="1.0" encoding="UTF-8"?> <ns0:TreeInfo xmlns:ns0="http://mynamespace.com"> <Header> <OrderNo>100</OrderNo> <Item> <ItemNo>1</ItemNo> <Product>Slime</Product> <Quantity>2</Quantity> </Item> <Item> <ItemNo>2</ItemNo> <Product>Gunge</Product> <Quantity>4</Quantity> </Item> </Header> <Header> <OrderNo>102</OrderNo> <Item> <ItemNo>1</ItemNo> <Product>Sludge</Product> <Quantity>55</Quantity> </Item> </Header> </ns0:TreeInfo> 将项目链接到标头的唯一因素是它们在源 xml 中的输出顺序。 请有人建议实现此目标的最佳方法。 xslt 新手,正在努力使其工作 本质上是 <xsl:template match="*:FlatInfo"> <xsl:for-each-group select="*" group-starting-with="Header"> <Header> <xsl:copy-of select="current-group()/(*/OrderNo, Item)"/> </Header> </xsl:for-each-group> </xsl:template>

回答 1 投票 0

XSLT 过滤模板

我有输入xml: 999.999.868-88 <

回答 1 投票 0

XSLT 3.0 转型

尝试转换 xml 并按 xslt 3.0 中的值和元素对节点进行分组 嘿伙计们,我有一个输入 xml,如下所示 尝试在 xslt 3.0 中转换 xml 并按值和元素对节点进行分组 嘿伙计们,我有一个输入 xml 如下 <?xml version='1.0' encoding='UTF-8'?> <Applications> <Application> <applicationId>280</applicationId> <cust_IDCheckIDCollation> <Option> <id>197249</id> </Option> </cust_IDCheckIDCollation> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>292</applicationId> <cust_IDCheckIDCollation> <Option> <id>197249</id> </Option> </cust_IDCheckIDCollation> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>280</applicationId> <cust_OnlineReferenceCheck> <Option> <id>197249</id> </Option> </cust_OnlineReferenceCheck> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>292</applicationId> <cust_OnlineReferenceCheck> <Option> <id>197249</id> </Option> </cust_OnlineReferenceCheck> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>280</applicationId> <cust_AustralianWorkRights> <Option> <id>197250</id> </Option> </cust_AustralianWorkRights> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>292</applicationId> <cust_AustralianWorkRights> <Option> <id>197250</id> </Option> </cust_AustralianWorkRights> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>280</applicationId> <cust_NationalPoliceCheck> <Option> <id>197249</id> </Option> </cust_NationalPoliceCheck> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> <Application> <applicationId>292</applicationId> <cust_NationalPoliceCheck> <Option> <id>197249</id> </Option> </cust_NationalPoliceCheck> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> </Application> </Applications> 我需要按 applicationId 将其分组,然后按元素名称对其进行子分组以删除重复元素。 预期产出 <Applications> <Application> <applicationId>280</applicationId> <cust_IDCheckIDCollation> <Option> <id>197249</id> </Option> </cust_IDCheckIDCollation> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> <cust_OnlineReferenceCheck> <Option> <id>197249</id> </Option> </cust_OnlineReferenceCheck> <cust_AustralianWorkRights> <Option> <id>197250</id> </Option> </cust_AustralianWorkRights> <cust_NationalPoliceCheck> <Option> <id>197249</id> </Option> </cust_NationalPoliceCheck> </Application> <Application> <applicationId>292</applicationId> <cust_IDCheckIDCollation> <Option> <id>197249</id> </Option> </cust_IDCheckIDCollation> <cust_overallduedilligencestatus> <Option> <id>197276</id> </Option> </cust_overallduedilligencestatus> <cust_OnlineReferenceCheck> <Option> <id>197249</id> </Option> </cust_OnlineReferenceCheck> <cust_AustralianWorkRights> <Option> <id>197250</id> </Option> </cust_AustralianWorkRights> <cust_NationalPoliceCheck> <Option> <id>197249</id> </Option> </cust_NationalPoliceCheck> </Application> <Applications> 在 xslt 3.0 中是否有更简单的方法来做到这一点。 我在 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:template match="/Applications"> <xsl:copy> <xsl:for-each-group select="Application" group-by="applicationId"> <xsl:copy> <xsl:for-each-group select="current-group()/*" group-by="name()"> <xsl:element name="{current-grouping-key()}"> <xsl:value-of select="(current-group())[1]"/> </xsl:element> </xsl:for-each-group> </xsl:copy> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet>``` 我想你想做: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/Applications"> <xsl:copy> <xsl:for-each-group select="Application" group-by="applicationId"> <xsl:copy> <xsl:copy-of select="applicationId"/> <xsl:for-each-group select="current-group()/(* except applicationId)" group-by="name()"> <xsl:copy-of select="current-group()[1]"/> </xsl:for-each-group> </xsl:copy> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet>

回答 1 投票 0

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