xslt 相关问题

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

XSLT 2.0 中的链接模板

我有一个非常简单的输入文件: ...

回答 1 投票 0

使用 nodeJS 中的参数和 saxon-js 将 XSLT 重用于不同的 XML 输入

我想使用 XSLT 将未知数量的不同但非常相似的结构化输入 XML 文档转换为单个输出 XML 格式。 我的平台是node.js,因此我正在研究...

回答 1 投票 0

如何迭代XSL并获取节点

我正在就我在尝试迭代和 XSLT 转换时面临的挑战问题与您联系。我有以下 XML 结构,我正在尝试获取值 AUFNR、BDMNG、

回答 1 投票 0

在 .NET 6 中使用 xsltc.exe 生成的程序集(XSLT 样式表)

我有一个 XSLT 样式表“Stylesheet.xsl”,我已使用 xsltc.exe 将其编译为“Stylesheet.dll” 该 DLL 包含在我的 .NET 6 中(net6.0 我有一个 XSLT 样式表“Stylesheet.xsl”,我已使用 xsltc.exe 将其编译为“Stylesheet.dll” 该 DLL 包含在我的 .NET 6 (<TargetFramework>net6.0</TargetFramework>) 项目中,用法如下: var xslCompiledTransform = new XslCompiledTransform(); xslCompiledTransform.Load(typeof(Stylesheet)); // ↑ System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlXml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified. xslCompiledTransform.Transform(@"..\..\..\input.xml", @"..\..\..\output.xml"); Load方法抛出FileNotFoundException,并显示消息“无法加载文件或程序集‘System.Data.SqlXml,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089’。系统找不到指定的文件。 ” 关于 xsltc.exe 的文档说明了以下内容: 脚本块仅在 .NET Framework 中受支持。 .NET Core 或 .NET 5 或更高版本不支持它们。 这严重暗示使用 xsltc.exe 编译的样式表应该在 .NET Core 或 .NET 5 或更高版本上工作(当不使用脚本块时),但在我的测试中却不起作用。 有谁知道为什么使用 xsltc.exe 编译的样式表不适用于 .NET 6 以及如何解决此问题? 更多详情 我在下面添加了有关我尝试过的更多详细信息。 请注意,我使用的样式表Stylesheet.xsl非常基本,没有使用特殊功能:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="/"> <output> <xsl:for-each select="input/book"> <booktitle> <xsl:value-of select="@title" /> </booktitle> </xsl:for-each> </output> </xsl:template> </xsl:stylesheet> 生成DLL的命令: "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\xsltc.exe" Stylesheet.xsl 在 SDK 样式的 .csproj 文件中引用 DLL: <ItemGroup> <Reference Include="Stylesheet"> <HintPath>.\Stylesheet.dll</HintPath> </Reference> </ItemGroup> input.xml:<input> <book title="First Title" /> <book title="Second Title" /> </input> output.xml 使用未编译的样式表执行转换时:<output> <booktitle>First Title</booktitle> <booktitle>Second Title</booktitle> </output> 我已经研究并发现其他人也有同样的问题,但还没有找到解决方案或解释为什么 Microsoft 文档隐式声明它应该可以工作,而在我的测试中却不起作用。 https://github.com/dotnet/runtime/issues/68129 在.NET Core 2.2中使用xsltc.exe生成的程序集? XslCompiledTransform.Load(type):无法加载文件或程序集“System.Data.SqlXml” System.IO.FileNotFoundException的堆栈跟踪: at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags) at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags) at System.Reflection.RuntimeMethodInfo.CreateDelegate(Type delegateType) at System.Xml.Xsl.XslCompiledTransform.Load(MethodInfo executeMethod, Byte[] queryData, Type[] earlyBoundTypes) at System.Xml.Xsl.XslCompiledTransform.Load(Type compiledStylesheet) at TestXslDotnet6.Program.Main(String[] args) in C:\Users\UserNameRedacted\Path\To\Repo\TestXslDotnet6\TestXslDotnet6\Program.cs:line 10 根据 GitHub 问题 .NET 6 不支持 XslCompiledTransform.Load(type(myXsltCompiled_dll)) 中的信息,看起来好像不支持,也不会支持。 2022年4月18日的评论说: 程序集 System.Data.SqlXml 包含命名空间 System.Xml.Xsl.Runtime,该命名空间在 .NET Core 中不存在。 根据移植指南,msxsl:script 在 .NET Core 上不可用。 .NET Framework 特定教程预计不起作用。 第二个人评论: 看起来 System.Data.SqlXml 是 SQLXML 的一部分,属于 据我所知,SQL Server org 不支持 .NET Core。 第三个人回复: 目前没有关于 SQLXML 和对 .NET 5+ 支持的计划, 我们还没有听到很多这方面的请求。我会 建议在此处开放用户声音以获得一些吸引力并 关于该主题的共识:https://aka.ms/sqlfeedback 所以,这就是您的答案:“msxsl:script 在 .NET Core 上不可用。.NET Framework 特定教程预计不起作用。”原因是非 .NET 组织必须使其成为可能,但没有计划这样做。他们没有意识到需求。 而且,他们承认该文档具有误导性。似乎在 2022 年 5 月对文档进行了更改,并创建了拉取请求:请注意,XSLT 脚本块仅限 .NET Framework。 我认识到这并没有为您提供解决方案或前进的道路,这令人失望。但这就是您问题的答案:.NET 6.0 根本不支持以这种方式进行转换。 虽然距离这个问题大约有两年了,但我还是想分享一下我为自己的目的所做的解决方法,因为我没有找到任何其他解决方案,可以帮助在基于 .NET Core 的转换中使用编译的 xslt dll。 因此,如果您想将 XslCompiledTransform 类与通过 xlstc.exe 生成的 dll 类型一起使用,请按照以下步骤操作: 生成dll类 xsltc.exe /class:Transform /out:Your.Assembly.dll 将 dll 反汇编为 ILL 代码 ildasm Your.Assembly.dll /out=Your.Assembly.ill 将 Your.Assembly.ill 中所有出现的 [System.Data.SqlXml] 替换为 [System.Private.Xml] 将你的IL编译回dll ilasm Your.Assembly.ill /dll 现在您可以将 Your.Assembly.dll 引用添加到您的 .NET Core 项目

回答 2 投票 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 将层次结构转换为新层次结构

嘿嘿! 我是 xslt 的新手,所以请原谅愚蠢的问题和错误:) 我有一个 xml 层次结构,想将其转换为新的层次结构。这很好用,但是有没有更简单/更优雅的方法? 哦...

回答 1 投票 0

将'?oxy_comments'转换为xml标签

嘿嘿! 有没有办法使用 xslt 将 ?oxy_comment_start 转换为有效的 xml 标签(如 app>)? 嘿! 有没有办法用 xslt 将 ?oxy_comment_start 转换为有效的 xml 标签(如 app></app>)? <?oxy_comment_start author="author" timestamp="today" comment="this: is a comment"?>THIS<?oxy_custom_end?> 我想要什么 <app> <lem> THIS </lem> <rdg> this: is a comment </rdg> </app> 我有什么: <xsl:template match="?oxy_comment_start"> <app> <lem> <xsl:apply-templates/> </lem> <rdg> <xsl:apply-templates select="@*[local-name() !='comment']"/> </rdg> </app> </xsl:template> 我收到错误消息: “描述:无法将表达式 {.?oxy_comment_start} 转换为模式” 有谁知道这是否可能以及如何实现? 您拥有的是两个处理指令,它们之间有一个文本节点。 您可以使用类似以下内容解析第一个处理指令: <xsl:template match="processing-instruction('oxy_comment_start')"> <app> <lem> <xsl:value-of select="following-sibling::text()[1]"/> </lem> <rdg> <xsl:value-of select="." /> </rdg> </app> </xsl:template> 这应该给你: <app> <lem>THIS</lem> <rdg>author="author" timestamp="today" comment="this: is a comment"</rdg> </app> 如何从内容中解析出注释取决于您使用的处理器。

回答 1 投票 0

此平台不支持XSLT编译

问题 我正在制作一个 UWP(通用 Windows 平台)应用程序。我试图将 .xml 和 .xsl 转换为 .html 文件以最终制作 pdf 文件,但 XslCompiledTransform 在加载 .xsl 时抛出错误...

回答 1 投票 0

Saxon HE 12.4 无法在 ErrorReporter 中提供错误位置

提供自定义 ErrorReporter 时,Saxon HE v12.4 无法提供错误 XSLT 指令的错误位置。 注意:这在 v9.8 中有效,因为报告提供了异常,其中包含...

回答 1 投票 0

使用 XSLT 将 XML 文本节点中的字符转换为下标或上标

我有一个结构如下的 XML 文件: 二氧化碳{2} 二氧化碳 我将如何使用 XSLT 来...

回答 1 投票 0

如何在多个线程中使用 net.sf.saxon.s9api.XsltTransformer 以避免影响性能和吞吐量?

在我的项目中,我尝试在多个线程中使用 net.sf.saxon.s9api.XsltTransformer 使用 java 中的同步,因为根据文档 XsltTransformer 不得在

回答 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

如何高效地并行运行大量文件的 XSLT 转换?

我每次都必须定期在 1 个文件夹内转换大量 XML 文件(至少 100K)(基本上,来自解压缩的输入数据集),我想学习如何以最有效的方式做到这一点。 .

回答 3 投票 0

从Java代码调用Xalan方法

我正在学习 XSLT,我发现 Xalan 真的很有帮助。我知道 Xalan 可以通过命令行命令使用,例如: java -classpath .;%XALAN_JAR% org.apache.xalan.xslt.Process -IN input.x...

回答 2 投票 0

XSLT 从 xpath 变量返回多个值

定义了以下变量,用于传入正确的 ID,一个用于区域类代码,一个用于扇区类代码: 150050&...

回答 2 投票 0

如何在XSLT中获取特定父节点的子节点?

我有一个类似这样的输入: ABC 西北

回答 1 投票 0

XSL-FO 表行分页符

我有一个简单的 xsl-fo 表,用于显示违规行为的集合。每个违规都是表中一组 3 行。每个组的高度可以不同,某些违规属性较大

回答 1 投票 0

SaxonJS.XPath.evaluate( fn:transform() ) 的结果不返回根文档节点

对于 NodeJs 工具,我必须使用 XSLT 执行简单的 XML 转换。 我想使用 SaxonJs,但我不想参与整个 xslt3/sef 的事情(xslt 发生变化并且该工具需要 r...

回答 1 投票 0

如何从字符串中删除小数点

在查找 iby_trxn_documents 表时,我们有来自 Oracle 的摘录 Value(发票金额)是一个字符串。 示例如下: 54380 19.80 我想: 54380 美元 0 美分 19 多尔...

回答 1 投票 0

XSLTProcessor 未运行

我一直在绞尽脑汁试图弄清楚为什么以下 XSLTProcessor 调用不起作用。 XSL-T 一直在绞尽脑汁试图找出为什么以下 XSLTProcessor 调用不起作用。 XSL-T <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xml:space="default"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/> <xsl:strip-space elements="*"/> <xsl:param name="include-header" select="'false'"/> <xsl:template match="/"> <!--xsl:element name="row"--> <xsl:text>{</xsl:text> <xsl:apply-templates select="*"/> <!--/xsl:element--> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="*[count(descendant::*)=0]"> <xsl:param name="parent"/> <xsl:variable name="quote" select="'&quot;'"/> <xsl:variable name="thisName" select="name()"/> <xsl:variable name="precedingSibling" select="count(preceding-sibling::*[name()=$thisName])+1"/> <xsl:variable name="parentChild" select="concat($parent, '.',$thisName, $precedingSibling)"/> <xsl:value-of select="concat($quote,$parentChild, $quote, ': ', $quote, ., $quote, ',')"/> <xsl:text> </xsl:text> </xsl:template> <xsl:template match="*"> <xsl:call-template name="recurse-descendents"/> </xsl:template> <xsl:template match="*[count(descendant::*)>0]"> <xsl:call-template name="recurse-descendents"/> </xsl:template> <xsl:template name="recurse-descendents"> <xsl:variable name="thisName" select="name()"/> <xsl:apply-templates select="*[count(descendant::*)=0]"> <xsl:with-param name="parent" select="concat($thisName, count(preceding-sibling::*[name()=$thisName])+1)"/> </xsl:apply-templates> <xsl:apply-templates select="*[count(descendant::*)>0]"/> </xsl:template> </xsl:stylesheet> 示例 XML <?xml version="1.0" encoding="UTF-8"?> <foods> <meats> <meat>Beef</meat> <meat>Chicken</meat> <meat>Lamb</meat> </meats> <fruits> <fruit>Orange</fruit> <fruit>Apple</fruit> <fruit>Banana</fruit> <fruit>Avacado</fruit> </fruits> <vegetables> <vegetable>Carrot</vegetable> <vegetable>Cellery</vegetable> <vegetable>Potato</vegetable> </vegetables> </foods> XML Spy 的输出(如预期) {"meats1.meat1": "Beef", "meats1.meat2": "Chicken", "meats1.meat3": "Lamb", "fruits1.fruit1": "Orange", "fruits1.fruit2": "Apple", "fruits1.fruit3": "Banana", "fruits1.fruit4": "Avacado", "vegetables1.vegetable1": "Carrot", "vegetables1.vegetable2": "Cellery", "vegetables1.vegetable3": "Potato", } 使用 XSLTProcessor 的 Javascript 代码(不起作用) async function GenerateTestCaseResponse(xml, testCase) { const domParser = new DOMParser(); const xsltProcessor = new XSLTProcessor(); const xslResponse = await fetch("transformer/generate-response-json.xslt"); const xslText = await xslResponse.text(); const xslStylesheet = domParser.parseFromString(xslText, "application/xml"); xsltProcessor.importStylesheet(xslStylesheet); var responseDomParser = new DOMParser(); var responseDocument = responseDomParser.parseFromString(xml, "text/xml"); var result = xsltProcessor.transformToDocument(responseDocument); console.log(result.body); return result; } 对 xsltProcessor.transformToDocument 的调用返回空,没有错误或异常。不知如何解决,如有任何想法,感激不尽。 正如评论中已经指出的,任意 XML 文档中都没有正文,您似乎无论如何都想使用输出方法文本和文本内容,因此请使用片段结果并访问其 textContent 属性,例如 const xsltSource = `<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xml:space="default"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/> <xsl:strip-space elements="*"/> <xsl:param name="include-header" select="'false'"/> <xsl:template match="/"> <!--xsl:element name="row"--> <xsl:text>{</xsl:text> <xsl:apply-templates select="*"/> <!--/xsl:element--> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="*[count(descendant::*)=0]"> <xsl:param name="parent"/> <xsl:variable name="quote" select="'&quot;'"/> <xsl:variable name="thisName" select="name()"/> <xsl:variable name="precedingSibling" select="count(preceding-sibling::*[name()=$thisName])+1"/> <xsl:variable name="parentChild" select="concat($parent, '.',$thisName, $precedingSibling)"/> <xsl:value-of select="concat($quote,$parentChild, $quote, ': ', $quote, ., $quote, ',')"/> <xsl:text> </xsl:text> </xsl:template> <xsl:template match="*"> <xsl:call-template name="recurse-descendents"/> </xsl:template> <xsl:template match="*[count(descendant::*)>0]"> <xsl:call-template name="recurse-descendents"/> </xsl:template> <xsl:template name="recurse-descendents"> <xsl:variable name="thisName" select="name()"/> <xsl:apply-templates select="*[count(descendant::*)=0]"> <xsl:with-param name="parent" select="concat($thisName, count(preceding-sibling::*[name()=$thisName])+1)"/> </xsl:apply-templates> <xsl:apply-templates select="*[count(descendant::*)>0]"/> </xsl:template> </xsl:stylesheet>`; const xmlSource = `<?xml version="1.0" encoding="UTF-8"?> <foods> <meats> <meat>Beef</meat> <meat>Chicken</meat> <meat>Lamb</meat> </meats> <fruits> <fruit>Orange</fruit> <fruit>Apple</fruit> <fruit>Banana</fruit> <fruit>Avacado</fruit> </fruits> <vegetables> <vegetable>Carrot</vegetable> <vegetable>Cellery</vegetable> <vegetable>Potato</vegetable> </vegetables> </foods>`; function GenerateTestCaseResponse(xmlSource, xsltSource) { const domParser = new DOMParser(); const xsltProcessor = new XSLTProcessor(); const xsltStylesheet = domParser.parseFromString(xsltSource, "application/xml"); xsltProcessor.importStylesheet(xsltStylesheet); var xmlDoc = domParser.parseFromString(xmlSource, "application/xml"); var result = xsltProcessor.transformToFragment(xmlDoc, xmlDoc).textContent; console.log(result); return result; } GenerateTestCaseResponse(xmlSource, xsltSource);

回答 1 投票 0

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