Tag: xslt

如何将String对象(包含XML)“转换”为现有JSP页面上的元素

目前,我有一个包含XML元素的String对象: String carsInGarage = garage.getCars(); 我现在想要将此String作为输入/流源(或某种源)传递,但我不确定选择哪一个以及如何实现它。 我查看的大多数解决方案都导入了包:javax.xml.transform并接受XML文件(stylerXML.xml)并输出到HTML文件(outputFile.html)(参见下面的代码)。 try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(“styler.xsl”)); transformer.transform(new StreamSource(“stylerXML.xml”), new StreamResult(new FileOutputStream(“outputFile.html”))); } catch (Exception e) { e.printStackTrace(); } 我想接受一个String对象并输出(使用XSL)到现有JSP页面中的元素。 我只是不知道如何实现这一点,即使看了上面的代码。 有人可以建议/协助。 我已经搜索了高低解决方案,但我无法解决任何问题。

通过java在xslt转换中获取错误

我正在尝试一个xsl转换,现在由一个java对象生成一个中间XML,并且再次传递XML以生成一个新的XML,而在xsl转换中,我收到错误,让我告诉你在我的下面我试过的一段代码。 下面是我的类,首先我创建对象,然后通过xstream生成中间XML InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage = new InvoiceReferenceNotificationMessage(); invoiceReferenceNotificationMessage.setInvoiceReference(“SM/8315”); invoiceReferenceNotificationMessage.setABSReference(“IRMA5456R157311”); invoiceReferenceNotificationMessage.setCurrency(“GBP”); invoiceReferenceNotificationMessage.setInvoiceAmount(255646); invoiceReferenceNotificationMessage.setPaidAmount(1246565); invoiceReferenceNotificationMessage.setBalanceAmount(0); invoiceReferenceNotificationMessage.setValueDate(new Date()); invoiceReferenceNotificationMessage.setRemarks(“abc”); InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage1 = new InvoiceReferenceNotificationMessage(); invoiceReferenceNotificationMessage1.setInvoiceReference(“SM/1655”); invoiceReferenceNotificationMessage1.setABSReference(“I1575656311”); invoiceReferenceNotificationMessage1.setCurrency(“EUR”); invoiceReferenceNotificationMessage1.setInvoiceAmount(25655546); invoiceReferenceNotificationMessage1.setPaidAmount(1255565645); invoiceReferenceNotificationMessage1.setBalanceAmount(0); invoiceReferenceNotificationMessage1.setValueDate(new Date()); invoiceReferenceNotificationMessage1.setRemarks(“abERRc”); Transformer xsltTransformer = null; Mail m = new Mail(); m.setInvoiceReferenceNotificationMessage(invoiceReferenceNotificationMessage); XStream xstream = new XStream(); xstream.alias(“brokermail”,Mail.class); String abc = xstream.toXML(m); //System.out.println(abc); m.setInvoiceReferenceNotificationMessage(invoiceReferenceNotificationMessage1); xstream.alias(“brokermail”,Mail.class); String def […]

Saxon XSLT转换:如何在转换期间失败时关闭输出流

我想用多个输出文件进行XSLT转换。 因为我使用了“xsl:result-document”。 转换失败时,应删除所有输出文件。 但是如果由“xsl:result-document”创建的文档生成失败,我的程序将无法再删除此文档。 我认为原因是,“xsl:result-document”创建了一个不同的OutputStream。 有谁知道如何关闭所有输出流? 编辑:我使用Saxon 9.5进行转换。 请参阅下面的源代码: public void simpleTransform(String sourcePath, String xsltPath, String outputPath) { String resultDir=outputPath+”/filename.html”; TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource ss = new StreamSource(new File(xsltPath)); StreamResult sr = new StreamResult(new File(resultDir)); Transformer transformer = tFactory.newTransformer(ss); try { transformer.transform(new StreamSource(new File(sourcePath)), sr); System.out.println(“Transformation finished!”); } catch (TransformerException te) { try { […]

是dyn:评估已知在Xalan-J 2.7.1中存在问题的扩展函数吗?

我很难过为什么以下示例程序拒绝正确应用我的样式表。 看来dyn:evaluate在Xalan 2.7.1中的dyn:evaluate是拒绝处理某些XPath变量。 在类路径中使用xalan-j运行以下程序会产生以下结果: package com.testing2.xslt; import java.io.*; import java.util.logging.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; public class DynEvaluateTransform { private static final String XSLT = “” + “\n” + “\n” + ” \n” + ” \n” + ” \n” + ” \n” + ” \n” + ” \n” + ” \n” + ” dyn:evaluate available\n” + […]

将绝对文件路径从java代码传递给xslt document()

在我的xslt中,我想查找一个xml文件。 我需要从java代码传递这个文件的路径。我有以下几点: … Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); transformer.setParameter(“mypath”, “/home/user/repository”); XSLT: … … 问题是我想将一个绝对的“基本”路径传递给xsl,我希望将其与实际的xml文件名(myfile.xml)结合起来。 在我看来, document考虑了相对于xsl位置的文件参数。 此外,我注意到该参数未从java代码中获取。 我使用JABX和默认的Xalan XSLT处理器(1.0)我尝试了许多基于其他SOpost传递参数的变体,但没有成功。

使用XSLT输出多个文件

我试图找到一个我发现使用XSLT 2.0输出多个文件工作的例子。 使用Saxon B 9.7.0.1和Java 1.6,我收到此错误: C:\ Documents and Settings \ Administrator \ Desktop \ saxon> java -jar saxon9.jar -s:input.xml -xsl:transform.xml transform.xml第15行出错:java.net.URISyntaxException:路径中的非法字符在索引20:file:/// C:/ Documents and Settings / Administrator / Desktop / saxon / output1 / test1.html at xsl:for-each(file:/ C:/ Documents%20and%20Settings / Administrator / Desktop / saxon / transform.xml#10)processing / tests / testrun [1]转换失败:报告了运行时错误 input.xml中 transform.xml

在XML上应用XSLT v.2

我编写了一个XSLT 2.0版本文件,当它应用于XML文件时,它会出现以下错误: ERROR: ‘Unsupported XSL element ‘http://www.w3.org/1999/XSL/Transform:sequence” 这是Java代码: TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(“Test.xslt”)); transformer.transform(new StreamSource(“Old.xml”),new StreamResult(new FileOutputStream(“New.xml”))); 有人可以帮我解决这个问题吗?

用命名空间替换XSLT?

如果我有一个带命名空间的xml并想要应用一些值替换,我需要更改什么? http://xslt.online-toolz.com/tools/xslt-transformation.php Alex Fiona 这会将名称值更改为“Johndoe”: JohnDoe 但是,如果我在非常标记之前有一个命名空间,例如: Alex Fiona

如何使用xpath编辑特定的xml

我有以下xml,使用xslt函数json-to-xml()生成。 我需要使用给定的xpath更新此xml,如结果xml中所示。 我需要java或xslt中的解决方案。 任何帮助将非常感激。 XML Lisa 200 applicaton/json ccc mmm 666 333 abc 2018 的XPath /Response/Payload/root/cars[2]/strength=999 /Response/Payload/root/bikes/model=2019 /Response/Headers/server=WebSphere /Response/Headers/Content-Type=text /Response/Payload/root/cars[2]/Capacity=555 /Response/Payload/root/cars[1]/model=mmm1 /Response/Payload/root/bikes/company=xyz /Response/Payload/root/cars[1]/company=ccc1 /Response/Headers/Status-Code=400 更新的结果XML WebSphere 400 text ccc1 mmm1 999 555 xyz 2019 我的尝试 我尝试使用xslt函数将此xml转换回json,然后使用com.jayway.jsonpath Jayway JsonPath库来解析/更改给定xpath上的json值。 然后最后使用xslt函数将json再次更改为xml。 这对我来说就像魅力一样! 但是在使用这个库之后我开始在我的应用程序的其他部分遇到问题:(。所有json请求体的发布请求开始给出400错误。错误是“错误400客户端发送的请求在语法上不正确”。我不能找出问题并且可能是由于不同的jar骗局。所以我正在尝试其他方式工作。任何其他库如Jayway JsonPath?或任何其他解决方案/建议将帮助很多。

获取元素的XPath列表

我有具有特定名称的元素的NodeList,我想拥有所有theese节点的XPath。 我找不到如何做到这一点的方法。 NodeList nList = doc.getElementsByTagName(“definition”); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); System.out.println(node.GET_XPATH()); } 我正在寻找像GET_XPATH()这样的方法 有人知道怎么做吗? 或者甚至可能吗? 如果有可能,XSLT也可以使用它,但更喜欢有人知道Java中的这种可能性。 原因:我需要一组指向XML库的指针。 用于定义元素的指针。 示例输入: experiment Experiment 输出: /odML/section/definition /odML/section/property[1]/definition /odML/section/property[2]/definition /odML/section/property[2]/value/definition /odML/definition