xslt-2.0 相关问题

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

如何在 xsl fo 中的表体第一行而不是表头添加连续文本?

我正在尝试使用 Apache FOP 在我的 pdf 中创建动态表。 我已经实现了大部分目标,还需要一些微调。 我在表头中使用了 fo:retrieve-table-marker 并且它有效

回答 1 投票 0

xpath 中原子值与节点的混淆

(以及如何避免翻筋斗) (撒克逊 PE 11.4) 考虑 (以及如何在不翻筋斗的情况下避免这种情况) (撒克逊 PE 11.4) 考虑 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <root> <xsl:for-each select="('a','b','D')"> <string> <xsl:value-of select="upper-case(.)"/> </string> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet> 反对任何输入(我永远无法解决使用初始模板并使其在氧气中工作) 所以输入是... <root/> 它输出 <root> <string>A</string> <string>B</string> <string>D</string> </root> (实际输出只是一个示例,这不是最终目标) 我想做的是创建一个 xpath 表达式,它执行大写 all in 1 表达式,并且我得到一系列大写字符串 所以...第一个猜测 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <root> <xsl:for-each select="('a','b','D')/upper-case(.)"> <string> <xsl:value-of select="."/> </string> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet> 天真地这似乎很合理,我只是将大写字母应用于序列中的每个“字符串”,并使用“/”作为管道运算符 但它抱怨 The required item type of the first operand of '/' is node(). The supplied value is an atomic value 啊..所以“/”希望“输入”是“node()”...我该怎么做?最好用相同的表达方式......即它伪xpath to-node(('a','b','D'))/upper-case(.) 您可以使用for... <xsl:for-each select="for $val in ('a','b','D') return upper-case($val)"> <string> <xsl:value-of select="."/> </string> </xsl:for-each> 但对我来说,在 xsl:value-of/@select 上使用 upper-case() 似乎更干净。

回答 1 投票 0

XSL 替换单个元素的命名空间 URI,但保留前缀

这是我的 XML: 这是我的 XML: <?xml version='1.0' encoding='utf-8'?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <wd:Unpost_Job_Request xmlns:wd="urn:com.test.report" wd:version="v40.2"> <wd:Business_Process_Parameters> <wd:Auto_Complete>true</wd:Auto_Complete> <wd:Run_Now>true</wd:Run_Now> <wd:Discard_On_Exit_Validation_Error>true</wd:Discard_On_Exit_Validation_Error> <wd:Comment_Data> <wd:Comment>Unposting Triggered by Automation</wd:Comment> </wd:Comment_Data> </wd:Business_Process_Parameters> <wd:Unpost_Job_Data> <wd:Job_Posting_Reference> <wd:ID wd:type="Job_Posting_ID">JOB_POSTING-3-23427</wd:ID> </wd:Job_Posting_Reference> </wd:Unpost_Job_Data> </wd:Unpost_Job_Request> </env:Body> </env:Envelope> 我需要复制整个文档,只更改以下命名空间: <wd:Unpost_Job_Request xmlns:wd="urn:com.test.report" <-- Changed to xmlns:wd="urn:com.final.report" wd:version="v40.2"> 所以最终的预期输出是: <?xml version='1.0' encoding='utf-8'?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <wd:Unpost_Job_Request xmlns:wd="urn:com.final.report" wd:version="v40.2"> <wd:Business_Process_Parameters> <wd:Auto_Complete>true</wd:Auto_Complete> <wd:Run_Now>true</wd:Run_Now> <wd:Discard_On_Exit_Validation_Error>true</wd:Discard_On_Exit_Validation_Error> <wd:Comment_Data> <wd:Comment>Unposting Triggered by Automation</wd:Comment> </wd:Comment_Data> </wd:Business_Process_Parameters> <wd:Unpost_Job_Data> <wd:Job_Posting_Reference> <wd:ID wd:type="Job_Posting_ID">JOB_POSTING-3-23427</wd:ID> </wd:Job_Posting_Reference> </wd:Unpost_Job_Data> </wd:Unpost_Job_Request> </env:Body> </env:Envelope> 这是我当前的 XSL: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wd="urn:com.test.report" exclude-result-prefixes="xs" version="2.0"> <xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="wd:Unpost_Job_Request"> <xsl:element name="{local-name(.)}"> <xsl:namespace name="wd">urn:com.final.report</xsl:namespace> <xsl:apply-templates select="node() | @*"/> </xsl:element> </xsl:template> </xsl:stylesheet> 返回: <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <Unpost_Job_Request xmlns:wd="urn:com.final.report" xmlns:wd_1="urn:com.test.report" wd_1:version="v40.2"> <wd:Business_Process_Parameters xmlns:wd="urn:com.test.report"> <wd:Auto_Complete>true</wd:Auto_Complete> <wd:Run_Now>true</wd:Run_Now> <wd:Discard_On_Exit_Validation_Error>true</wd:Discard_On_Exit_Validation_Error> <wd:Comment_Data> <wd:Comment>Unposting Triggered by Automation</wd:Comment> </wd:Comment_Data> </wd:Business_Process_Parameters> <wd:Unpost_Job_Data xmlns:wd="urn:com.test.report"> <wd:Job_Posting_Reference> <wd:ID wd:type="Job_Posting_ID">JOB_POSTING-3-23427</wd:ID> </wd:Job_Posting_Reference> </wd:Unpost_Job_Data> </Unpost_Job_Request> </env:Body> </env:Envelope> 因此,它不是替换现有的 xmlns:wd URI,而是添加一个新的命名空间并将“_1”附加到旧的命名空间,然后将不需要的 xmlns:wd 添加到另一个元素。我尝试了在这里找到的一些解决方案,但以上是我最接近目标的解决方案。其他解决方案添加了额外的命名空间。 要获得显示的确切结果,您必须将旧命名空间中的所有元素和属性移动到新命名空间中: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:old="urn:com.test.report" xmlns:wd="urn:com.final.report" exclude-result-prefixes="old"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="old:*" > <xsl:element name="wd:{local-name(.)}"> <xsl:apply-templates select="node() | @*"/> </xsl:element> </xsl:template> <xsl:template match="@old:*"> <xsl:attribute name="wd:{local-name(.)}" select = "."/> </xsl:template> </xsl:stylesheet>

回答 1 投票 0

使用 xslt 操作 xml 文件中元素中的值

我希望能够删除或替换 xml 文件中元素值内不必要的文本,并且我希望使用 XSLT 转换来实现此目的。 在此示例文件中,我想删除特定的

回答 1 投票 0

使用 xslt 替换 xml 文件中元素中的值

我想删除 xml 文件中元素值内不必要的文本,并且我想使用 XSLT 转换来做到这一点。 在此示例文件中,我想删除特定标签,例如 、 我想删除 xml 文件中元素值内不必要的文本,并且我想使用 XSLT 转换来做到这一点。 在此示例文件中,我想删除 <br>、<preffix>、<suffix> 元素内部值中的特定标签。会有很多<Value>元素。我不想更改此文件的结构,因此这应该类似于副本,但具有删除特定文本的逻辑。我尝试使用模板和复制,但不知何故我无法将它们连接在一起。 如果你们中的任何人可以帮助我或给我应该遵循的提示,我将不胜感激。 <Product> 输出文件应如下所示: <ProductInfo> <Products> <Product> <Name>xyz</Name> <Values> <Value><br/>test</Value> <-- remove <br/> <Value><preffix/>test2</Value> <-- remove <preffix> <Value><suffix/>test3</Value> <-- remove <suffix/> </Values> </Product> <Product> <Name>xyz</Name> <Values> <Value><br/>test</Value> <-- remove <br/> <Value><preffix/>test2</Value> <-- remove <preffix> <Value><suffix/>test3</Value> <-- remove <suffix/> </Values> </Product> </Products> </ProductInfo> 以下样式表: XSLT 1.0 <ProductInfo> <Products> <Product> <Name>xyz</Name> <Values> <Value>test</Value> <Value>test2</Value> <Value>test3</Value> </Values> </Product> <Product> <Name>xyz</Name> <Values> <Value>test</Value> <Value>test2</Value> <Value>test3</Value> </Values> </Product> </Products> </ProductInfo> 将通过仅返回<xsl:stylesheet version="1.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="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="Value"> <xsl:copy> <xsl:value-of select="."/> </xsl:copy> </xsl:template> </xsl:stylesheet> 元素中包含的任何标记字符串值 - 即“按文档顺序排列元素节点的所有文本节点后代的字符串值的串联”。 您可以通过身份转换以及与您要删除/删除的内容相匹配的附加空模板来完成此操作。 Value 您可以为每个匹配模式使用单独的空匹配模板,而不是使用 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!--empty template matching the elements that we want to drop and not appear in the result--> <xsl:template match="Value/br | Value/prefix | Value|suffix"/> </xsl:stylesheet> 联合。此外,如果您想删除出现在 | 元素内部的所有元素,您可以使用 Value 进行更通用的匹配。

回答 2 投票 0

错误:无法使用 Saxon EE 的 XSLT 2.0 找到匹配的 0 参数函数(许可证文件位于与 JAR 相同的文件夹中)

我正在使用 saxon EE 处理器通过 XSLT-2.0 进行 XML 转换。但它给出了 XSL 文件错误。 以下是 XSL 文件的代码 我正在使用 saxon EE 处理器通过 XSLT-2.0 进行 XML 转换。但它给出了 XSL 文件错误。 以下是XSL文件的代码 <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:setfile ="java:com.output.extensionFile"> <xsl:param name="outDir" select="setfile:getCurrentDir(setfile:new())"/> </xsl:stylesheet> 下面是我们调用转换器以将 XML 转换为 HTML 的代码。 { javax.xml.transform.TransformerFactory tFactory = new EnterpriseTransformerFactory(); XslImportResolver myResolve = new XslImportResolver(); tFactory.setURIResolver( myResolve ); javax.xml.transform.Transformer transformer = tFactory.newTransformer (new javax.xml.transform.stream.StreamSource(xslLocation)); Registry registry = Registry.getRegistry( this ); transformer.transform( new StreamSource( xmlLocation ), new StreamResult( new FileOutputStream( htmlLocation ) ) ); } 导入 Java 类的 Java 代码 public class extensionFile { // Empty Constructor public extensionFile() { } public Object getCurrentDir() { return ReportStatic.getCurrentDir(); } } 我们收到以下错误: 第 78 行第 73 列 xsl:param/@select 表达式中 {...e:getCurrentDir(setfile:new...} 附近的 char 22 处出现静态错误: XPST0017:找不到名为 Q{java:com.output.extensionFile}new() 的匹配 0 参数函数。用于诊断 调用 Java 方法,使用 -TJ 命令行选项或设置 Configuration 属性 功能键.TRACE_EXTERNAL_FUNCTIONS 您是否运行了建议的诊断程序? 根据给出的信息,最可能的解释是(a)该类的全名不是您所建议的,或者(b)该类不在类路径上。 -TJ 诊断应该会揭示解释。

回答 1 投票 0

xsl:fo 如何绘制复选框

伙计们,我需要在我的 xsl:fo 文档中添加一个复选框,所以问题是,它们是 fo 中的一种方式,还是需要一张图片(图形)? 我使用 FOP 和 xslt 2.0 这是复选框的图片

回答 4 投票 0

在 XSLT 中获取树的最里面的元素

我有一个应用程序可以打印出类似于下面的异常 某事 <某事

回答 1 投票 0

为什么 - result-document method="text" - 导出 xml 声明?

撒克逊11.4 如果我运行这个 撒克逊11.4 如果我运行这个 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0"> <xsl:template match="/"> <xsl:result-document method="text" encoding="utf-8"> <xsl:text>foo</xsl:text> </xsl:result-document> </xsl:template> </xsl:stylesheet> 我希望有一个文本文档 foo 但是我明白了 <?xml version="1.0" encoding="UTF-8"?>foo 我试图根据传递的参数动态尝试选择和输出格式,但显然如果我想要文本输出,我不希望其中有 xml 声明。 附注 输入文档可以是任何有效的 xml(除非我遗漏了某些内容) 所以 <foo/> 您没有向我们展示输入是什么,也没有解释您到底如何运行转换并查看结果,但对我来说(当前使用 SaxonJ HE 11.5)XML 工作台,没有输入,以及代码 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0"> <xsl:template name="xsl:initial-template"> <xsl:result-document method="text" encoding="utf-8"> <xsl:text>foo</xsl:text> </xsl:result-document> </xsl:template> </xsl:stylesheet> 只给 foo 作为唯一且主要的结果。 所以不太清楚你在做什么或以什么方式(命令行,一些API,一些编辑器)使用Saxon并得到你在问题中显示的结果。

回答 1 投票 0

使用 XSLT 2.0 将 xml 标签中存在的 Json 文件解析为 XML 单独标签

需要 xslt 2.0 的帮助才能实现以下要求。 输入: ”{ “成功”:真实, “错误”:[], “元素”:[ { “代码”:...

回答 1 投票 0

substring-after() 函数似乎删除了字符串中的其他格式

假设我在 XML 标记中有以下文本: !!!关于这个@v varname需要注意的事情 我想使用 XSL-FO 代码将三个感叹号(!!!)后面的文本格式化为 st... 假设我在 XML 标记中有此文本: <p>!!! Something to note about this @v varname<p> 我想使用 XSL-FO 代码将三个感叹号 (!!!) 后面的文本格式化为样式注释,同时将 @v 符号后面的文本设置为斜体。例如,注释看起来像这样: 注意: 需要注意的事项 varname 我下面的代码在大部分情况下都有效,只是“varname”在输出中没有斜体。我对编写 XSL-FO 不太熟练,但我猜测它与似乎只输出纯文本的 substring-after() 函数有关。但是,我似乎找不到解决方法。我应该采取什么不同的做法? <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:opentopic="http://www.idiominc.com/opentopic" xmlns:opentopic-index="http://www.idiominc.com/opentopic/index" xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function" xmlns:dita2xslfo="http://dita-ot.sourceforge.net/ns/200910/dita2xslfo" xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot" xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder" exclude-result-prefixes="dita-ot ot-placeholder opentopic opentopic-index opentopic-func dita2xslfo xs" version="2.0"> <xsl:template match="text()[starts-with(., '!!!')]" priority="5" name="note"> <fo:block xsl:use-attribute-sets="note__common note__note"> <xsl:call-template name="commonattributes"/> <fo:external-graphic src="url({concat($artworkPrefix, 'Customization/OpenTopic/common/artwork/NOTE.png')})" content-width="scale-to-fit" width="23px"/> <fo:block xsl:use-attribute-sets="note__text__note"> <fo:inline xsl:use-attribute-sets="note__label">NOTE: </fo:inline> <xsl:value-of select="substring-after(., '!!!')"/> </fo:block> </fo:block> </xsl:template> <xsl:template match="text()[contains(., '@v')]" name="varname" priority="4"> <xsl:analyze-string select="." regex="@v\s+([!-~]+)"> <xsl:matching-substring> <fo:inline font-family="Roboto" font-style="italic"> <xsl:value-of select="regex-group(1)"/> </fo:inline> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> </xsl:stylesheet> 使用 xsl:value-of 只会为您提供一个计算文本节点。不会进行任何其他处理,因此您的其他模板匹配 text() 将永远不会被匹配。 此外,如果您使用 xsl:apply-templates,则其他 text() 模板将无法工作,因为 substring-after() 返回 xs:string 而不是 text() 节点。 作为替代方案,尝试使用 xsl:next-match 并删除其他模板中的 !!!... <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="2.0"> <xsl:output indent="true"/> <xsl:template match="text()[starts-with(., '!!!')]" priority="5" name="note"> <fo:block> <fo:external-graphic src="TBD.png" content-width="scale-to-fit" width="23px"/> <fo:block> <fo:inline>NOTE: </fo:inline> <xsl:next-match/> </fo:block> </fo:block> </xsl:template> <xsl:template match="text()[contains(., '@v')]" name="varname" priority="4"> <xsl:analyze-string select="." regex="(^!!!\s*)?(.*?)@v\s+([!-~]+)"> <xsl:matching-substring> <xsl:value-of select="regex-group(2)"/> <fo:inline font-family="Roboto" font-style="italic"> <xsl:value-of select="regex-group(3)"/> </fo:inline> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> </xsl:stylesheet> 小提琴:http://xsltfiddle.liberty-development.net/jyH7UDK/1 两个模板都匹配文本节点,但第一个模板具有更高的优先级,因此使用第一个模板。如果您希望应用两个模板规则,则需要通过显式应用模板来进行安排,例如将第一个模板规则的内部 fo:block 更改为 <fo:block xsl:use-attribute-sets="note__text__note"> <fo:inline xsl:use-attribute-sets="note__label">NOTE: </fo:inline> <xsl:variable name="remainder" as="text()"> <xsl:value-of select="substring-after(., '!!!')"/> <xsl:variable> <xsl:apply-templates select="$remainder"/> </fo:block>

回答 2 投票 0

注释 <xref> 标签并保持文本为纯文本

如果 xref/@href 属性值与section/@id 属性值不匹配,我想注释外部参照标签并保持文本为纯文本。 我已经创建了 xsl 代码来注释外部参照标签,但是你...

回答 1 投票 0

如果来自另一个节点的规则适用,则添加位置编号,但按照当前节点的顺序

输入: B缺乏 输入: <ROOT> <TEMPLATE style="test"> <ATTRIBUTE name="Color"><VALUE><UNIT>B</UNIT><UNIT>lack</UNIT></VALUE></ATTRIBUTE> </TEMPLATE> <TEMPLATE style="test"> <ATTRIBUTE name="Something"><VALUE>1235</VALUE></ATTRIBUTE> <ATTRIBUTE name="Name"><VALUE><UNIT>Hello</UNIT></VALUE></ATTRIBUTE> <ATTRIBUTE name="Height"><VALUE>12</VALUE></ATTRIBUTE> </TEMPLATE> <TEMPLATE style="something-else"> <ATTRIBUTE name="Test"><VALUE>Hey</VALUE></ATTRIBUTE> </TEMPLATE> <TEMPLATE style="footnotes"> <ATTRIBUTE name="FOOTNOTE_Test"><VALUE>not-relevant</VALUE></ATTRIBUTE> <ATTRIBUTE name="FOOTNOTE_Name"><VALUE>whatever</VALUE></ATTRIBUTE> <ATTRIBUTE name="FOOTNOTE_Color"><VALUE>Some value</VALUE></ATTRIBUTE> </TEMPLATE> <ROOT> 所需输出: <ROOT> <TEMPLATE style="test"> <ATTRIBUTE name="Color"><VALUE><UNIT>B</UNIT><UNIT>lack</UNIT> *1</VALUE></ATTRIBUTE> </TEMPLATE> <TEMPLATE style="test"> <ATTRIBUTE name="Something"><VALUE>1235</VALUE></ATTRIBUTE> <ATTRIBUTE name="Name"><VALUE><UNIT>Hello</UNIT> *2</VALUE></ATTRIBUTE> <ATTRIBUTE name="Height"><VALUE>12</VALUE></ATTRIBUTE> </TEMPLATE> <TEMPLATE style="something-else"> <ATTRIBUTE name="Test"><VALUE>Hey</VALUE></ATTRIBUTE> </TEMPLATE> <TEMPLATE style="footnotes"> <ATTRIBUTE name="FOOTNOTE_Test"><VALUE>not-relevant</VALUE></ATTRIBUTE> <ATTRIBUTE name="FOOTNOTE_Name"><VALUE>whatever</VALUE></ATTRIBUTE> <ATTRIBUTE name="FOOTNOTE_Color"><VALUE>Some value</VALUE></ATTRIBUTE> </TEMPLATE> <ROOT> 在我的样式为“test”的模板中,有些属性的名称+前缀“FOOTNOTE_”可以与模板“footnotes”中的属性名称匹配。如果名称匹配,则应将 " * {position}" 添加到属性值中。该位置计算已设置的脚注数量,但顺序基于测试样式属性而不是脚注。 我已经尝试过各种分组尝试和 for-each 循环,但它们从未达到预期的结果。 我正在使用 XSLT 2.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:key name="fn" match="TEMPLATE[@style='footnotes']/ATTRIBUTE" use="substring-after(@name, 'FOOTNOTE_')" /> <xsl:template match="/"> <xsl:variable name="temp"> <xsl:apply-templates mode="temp"/> </xsl:variable> <xsl:apply-templates select="$temp/ROOT"/> </xsl:template> <!-- identity transform --> <xsl:template match="@*|node()" mode="#all"> <xsl:copy> <xsl:apply-templates select="@*|node()" mode="#current"/> </xsl:copy> </xsl:template> <xsl:template match="TEMPLATE[@style='test']/ATTRIBUTE[key('fn', @name)]/VALUE" mode="temp"> <xsl:copy> <xsl:apply-templates/> <NUMBER/> </xsl:copy> </xsl:template> <xsl:template match="NUMBER"> <xsl:text> *</xsl:text> <xsl:number count="NUMBER" level="any"/> </xsl:template> </xsl:stylesheet> 请注意,结果是混合内容的 XML,这是您通常想要避免的。 试试这个: <?xml version="1.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="footnote" match="TEMPLATE[@style='footnotes']/ATTRIBUTE" use="substring-after(@name,'FOOTNOTE_')"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="TEMPLATE[@style='test']/ATTRIBUTE/VALUE"> <xsl:variable name="name" select="parent::*/@name"/> <xsl:copy> <xsl:apply-templates select="@* | node()"/> <xsl:variable name="footnode" as="element()?" select="key('footnote',$name)"/> <xsl:if test="$footnode"> <xsl:value-of select="concat(' *',(count(parent::*/preceding-sibling::*) + 1))"/> </xsl:if> </xsl:copy> </xsl:template> </xsl:stylesheet>

回答 2 投票 0

需要 XSLT 帮助:显示两个不同日期之间的所有日期

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

回答 1 投票 0

XSLT 分组为标题和位置

我有以下可用的 xml 导出: 2022-08-09T08:46:00 ... 我有以下可用的 xml 导出: <?xml version='1.0' encoding='UTF-8'?> <document> <header> <creation-date>2022-08-09T08:46:00</creation-date> <SequenceOfDocument>10</SequenceOfDocument> </header> <businessobjects> <Reservation> <BeginDateTime>2022-07-29T16:00:00</BeginDateTime> <OrderNumber>606.00</OrderNumber> <Person> <UsrAddress> <Code>0393</Code> </UsrAddress> </Person> <TotalActualCostExclVAT>30.00</TotalActualCostExclVAT> <ParentOrderRef/> </Reservation> <Reservation> <BeginDateTime>2022-07-29T16:00:00</BeginDateTime> <OrderNumber>606.01</OrderNumber> <RefBODefinitionUserDefined>UsrReservationEquipment</RefBODefinitionUserDefined> <Person> <UsrAddress> <Code>0393</Code> </UsrAddress> </Person> <TotalActualCostExclVAT>40.00</TotalActualCostExclVAT> <ParentOrderRef>606.00</ParentOrderRef> </Reservation> <Reservation> <BeginDateTime>2022-07-29T16:00:00</BeginDateTime> <OrderNumber>607.00</OrderNumber> <RefBODefinitionUserDefined>UsrReservationEquipment</RefBODefinitionUserDefined> <Person> <UsrAddress> <Code>0500</Code> </UsrAddress> </Person> <TotalActualCostExclVAT>50.00</TotalActualCostExclVAT> <ParentOrderRef></ParentOrderRef> </Reservation> </businessobjects> </document> 我想通过 XSLT 进行所有操作,按以下方式分组:/Person/UsrAddress/Code 结果应该是: <SalesOrderHeader> <SalesOrderHeaderFields> <CustomerNumber>0393</CustomerNumber> </SalesOrderHeaderFields> <ItemFields> <_USERFIELD1>606.00</_USERFIELD1> </ItemFields> <ItemFields> <_USERFIELD1>606.01</_USERFIELD1> </ItemFields> </SalesOrderHeader> <SalesOrderHeader> <SalesOrderHeaderFields> <CustomerNumber>0500</CustomerNumber> </SalesOrderHeaderFields> <ItemFields> <_USERFIELD1>607.00</_USERFIELD1> </ItemFields> </SalesOrderHeader> 我已经尝试过: <xsl:for-each-group select="Reservation" group-by="/Person/UsrAddress/Code"> <xsl:for-each select="current-group()"> 但我没有将它们按人员/用户地址/代码分组。我不会像示例中那样将它们分组。也许有人可以给我提示? 这里有两种解决方案,一种使用 XSLT 1.0,另一种使用 XSLT 2.0 基于您的标签。 XSLT 2.0 解决方案 使用 xsl:for-each-group 指令。 <?xml version="1.0" encoding="UTF-8"?> <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:template match="//document"> <!-- Create SalesOrderHeader/SalesOrderHeaderFields/CustomerNumnber elements based on unique Person/UsrAddress/Code values --> <xsl:for-each-group select="businessobjects/Reservation" group-by="Person/UsrAddress/Code"> <xsl:element name="SalesOrderHeader"> <xsl:element name="SalesOrderHeaderFields"> <xsl:element name="CustomerNumber"> <xsl:value-of select="current-grouping-key()"/> </xsl:element> </xsl:element> <!-- Create ItemFields/_USERFIELD1 elements grouped by Person/UsrAddress/Code values --> <xsl:for-each select="current-group()"> <xsl:element name="ItemFields"> <xsl:element name="_USERFIELD1"> <xsl:value-of select="OrderNumber" /> </xsl:element> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> 参见 2.0 Fiddle。 XSLT 1.0 解决方案 使用Muenchien Method进行分组。 <?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" version="1.0" encoding="UTF-8" indent="yes"/> <!-- Create Key based on the Code element --> <xsl:key name="unique-codes" match="//Reservation" use="Person/UsrAddress/Code" /> <xsl:template match="//document"> <!-- Create SalesOrderHeader/SalesOrderHeaderFields/CustomerNumnber elements based on unique Code values --> <xsl:for-each select="//Reservation[count(. | key('unique-codes', Person/UsrAddress/Code)[1]) = 1]"> <xsl:sort select="Code" /> <xsl:element name="SalesOrderHeader"> <xsl:element name="SalesOrderHeaderFields"> <xsl:element name="CustomerNumber"> <xsl:value-of select="Person/UsrAddress/Code"/> </xsl:element> </xsl:element> <!-- Create ItemFields/_USERFIELD1 elements grouped by unique Code values --> <xsl:for-each select="key('unique-codes', Person/UsrAddress/Code)"> <xsl:sort select="Code" /> <xsl:element name="ItemFields"> <xsl:element name="_USERFIELD1"> <xsl:value-of select="OrderNumber" /> </xsl:element> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:template> </xsl:stylesheet> 参见 1.0 Fiddle。 值得注意的是,要使其有效XML,您需要一个根标签来将其包装起来(即<SalesOrders>)未包含在我的上述解决方案中,如下所示: <SalesOrders> <SalesOrderHeader> <SalesOrderHeaderFields> <CustomerNumber>0393</CustomerNumber> </SalesOrderHeaderFields> <ItemFields> <_USERFIELD1>606.00</_USERFIELD1> </ItemFields> <ItemFields> <_USERFIELD1>606.01</_USERFIELD1> </ItemFields> </SalesOrderHeader> <SalesOrderHeader> <SalesOrderHeaderFields> <CustomerNumber>0500</CustomerNumber> </SalesOrderHeaderFields> <ItemFields> <_USERFIELD1>607.00</_USERFIELD1> </ItemFields> </SalesOrderHeader> </SalesOrders>

回答 1 投票 0

如何删除“pub-id”中的“斜体”元素,“pub-id”中不允许出现“斜体”元素

我们正在尝试将任何标签移动到节元素下,如果标签是节元素的前同级和后同级。 请看下面的例子并提出建议! 谢谢你

回答 1 投票 0

XSLT 可同时分组并删除重复项

下面是我的输入 XML。我想根据用户名对 XML 下面进行分组,并删除 HierarchyLocation 中的任何重复项 下面是我的输入 XML ...

回答 2 投票 0

Saxon XSLT SQL 连接标题

我有这个 html,我想将其解析为多个部分并插入到 SQLite 数据库中: 标题 ...

回答 1 投票 0

不允许将多个项目的序列作为 fn:substring() 的第一个参数

我在xslt中使用子字符串时遇到此错误,错误消息很清楚,因此我尝试将多个序列值放入变量中并使用变量的子字符串,但它不起作用

回答 2 投票 0

XSLT:使用内容表元数据的递归模板

在这里摆弄。我正在尝试从内容表元数据创建一个唯一标识符,以供将来在文本数据库中使用。我使用 编写了一个递归调用模板 小提琴在这里。我正在尝试从内容表元数据创建一个唯一标识符,以供将来在文本数据库中使用。我使用 <xsl:for-each.. 编写了一个递归调用模板,但我没有得到预期的结果。 来源: <html lang="en"> <head> <title>Title</title> </head> <body> <h1 data-toc="1" data-stub="Title1">Title 1—General</h1> <h2 data-toc="5" data-stub="Part1">PART 1—DEFINITIONS</h2> <h3 data-toc="9" data-stub="Sec1">§ 1 Definitions.</h3> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec1.1">§ 1.1 Foo.</h3> <p>foo</p> <p>foo</p> <h2 data-toc="5" data-stub="Part2">PART 2—THE COMMITTEE</h2> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec2">§ 2 Definitions.</h3> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec2.1">§ 2.1 Foo.</h3> <p>foo</p> <p>foo</p> <h2 data-toc="5" data-stub="Part3">PART 3—THE COUNCIL</h2> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec3">§ 3 Definitions.</h3> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec3.1">§ 3.1 Foo.</h3> <p>foo</p> <p>foo</p> </body> </html> 样式表: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xhtml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="*[@data-toc]"> <xsl:variable name="build-callcode"> <xsl:call-template name="build-call-code"> <xsl:with-param name="this-toc-level" select="@data-toc"/> <xsl:with-param name="this-stub" select="@data-stub"/> </xsl:call-template> </xsl:variable> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:attribute name="data-callcode" select="$build-callcode"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template name="build-call-code"> <xsl:param name="this-toc-level"/> <xsl:param name="this-stub"/> <xsl:for-each select="preceding::*[@data-toc &lt; $this-toc-level][1]"> <xsl:call-template name="build-call-code"> <xsl:with-param name="this-toc-level" select="@data-toc"/> <xsl:with-param name="this-stub" select="concat(@data-stub, $this-stub)"/> </xsl:call-template> <xsl:value-of select="concat(@data-stub, $this-stub)"/> </xsl:for-each> </xsl:template> </xsl:stylesheet> 期望的结果: <html lang="en"> <head> <title>Title</title> </head> <body> <h1 data-toc="1" data-stub="Title1" data-callcode="Title1">Title 1—General</h1> <h2 data-toc="5" data-stub="Part1" data-callcode="Title1Part1">PART 1—DEFINITIONS</h2> <h3 data-toc="9" data-stub="Sec1" data-callcode="Title1Part1Sec1">§ 1 Definitions.</h3> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec1.1" data-callcode="Title1Part1Sec1.1">§ 1.1 Foo.</h3> <p>foo</p> <p>foo</p> <h2 data-toc="5" data-stub="Part2" data-callcode="Title1Part2">PART 2—THE COMMITTEE</h2> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec2" data-callcode="Title1Part2Sec2">§ 2 Definitions.</h3> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec2.1" data-callcode="Title1Part2Sec2.1">§ 2.1 Foo.</h3> <p>foo</p> <p>foo</p> <h2 data-toc="5" data-stub="Part3" data-callcode="Title1Part3">PART 3—THE COUNCIL</h2> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec3" data-callcode="Title1Part3Sec3">§ 3 Definitions.</h3> <p>foo</p> <p>foo</p> <h3 data-toc="9" data-stub="Sec3.1" data-callcode="Title1Part3Sec3.1">§ 3.1 Foo.</h3> <p>foo</p> <p>foo</p> </body> </html> 试试这个: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xhtml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="*[@data-toc]"> <xsl:variable name="build-callcode"> <!-- No need to call the template with any params --> <xsl:call-template name="build-call-code"/> </xsl:variable> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:attribute name="data-callcode" select="$build-callcode"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template name="build-call-code"> <xsl:variable name="this-toc-level" select="@data-toc"/> <!-- Since all nodes are siblings let's use preceding-sibling::* --> <xsl:for-each select="preceding-sibling::*[@data-toc &lt; $this-toc-level][1]"> <!-- No need to call the template with any params --> <xsl:call-template name="build-call-code"/> </xsl:for-each> <!-- Put the current @data-stub AFTER for-each--> <xsl:value-of select="@data-stub"/> </xsl:template> </xsl:stylesheet> 使用 XSLT 3(无论如何,当前支持的版本,例如 Saxon 都是 XSLT 3 处理器),您可以使用 xsl:accumulators: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all" version="3.0"> <xsl:accumulator name="data-toc" as="xs:integer*" initial-value="()"> <xsl:accumulator-rule match="*[@data-toc]" select="let $current-data-toc := xs:integer(@data-toc) return ($value[. lt $current-data-toc], $current-data-toc)"/> </xsl:accumulator> <xsl:accumulator name="data-call-code" as="xs:string*" initial-value="()"> <xsl:accumulator-rule match="*[@data-toc]" select="let $count := count(accumulator-before('data-toc')) return $value[position() lt $count], @data-stub"/> </xsl:accumulator> <xsl:mode on-no-match="shallow-copy" use-accumulators="data-toc data-call-code"/> <xsl:template match="*[@data-toc]"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:attribute name="data-callcode" select="accumulator-before('data-call-code') => string-join()"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>

回答 2 投票 0

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