xslt

Calling a function in XSLT

假如想象 提交于 2021-01-28 04:42:26
问题 I try to run one of the functions which are linked bellow in my own stylesheet. But I dont know how. Here is an xsltransform.net demo . And here are the functions I want to run: func 1 func 2 回答1: Assuming an XSLT 2.0 processor like Saxon 9 you can use xsl:function as follows: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:func="http://example.com/mf"> <xsl:output method="html" indent="yes"/> <xsl:strip-space

xslt remove table column when all specific value

时光毁灭记忆、已成空白 提交于 2021-01-28 03:23:36
问题 Using XSLT, I need to remove a complete table column (header + body cells) when a column contains only "0.00" or "-". i.e. If all the values in the cells of one or more columns are 0.00/- then the whole column(s) should be removed. 回答1: I have assumed that you mean't to say if all the data cells of the column are 0.00/- then remove it, not just one of them. If I have misunderstood, please advise and I will update the solution style-sheets accordingly. There are a lot of different ways and

Java Transformer how to ignore namespaces

隐身守侯 提交于 2021-01-28 02:05:28
问题 I have to transform XML to XHTML but the XML defines a namespace xmlns='http://www.lotus.com/dxl' which is never used in the whole XML therefore the parser won't parse anything ... Is there a way I ignore namepsaces? I am using the Oracle java transformer import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory Or are there any better libraries? 回答1: No, you can't ignore namespaces. If the namespace declaration xmlns='http://www.lotus.com/dxl' appears in the

The Writer is closed or in error state

大憨熊 提交于 2021-01-27 21:16:49
问题 While calling XslCompiledTransform.Transform() method I get this exception : The Writer is closed or in error state. Anyone know what it means? 回答1: It means that...The Writer is closed or in error state. Show us the surrouding code. It looks like you have a StreamWriter associated with that object that has been disposed or threw an error. For example: using( var stream = new SomeStream() ) using( var streamWriter = new StreamWriter() ) { someObj.SomeStreamWriter = streamWriter; // ... } //

Grouping with xslt and child nodes

痞子三分冷 提交于 2021-01-27 19:35:33
问题 I have tried some of the examples here, but I still can't get the correct output. I haven't worked much with XSLT before. I want to group on the "Detail" element and get all the "Data" elements matching that group as children to the "Detail" element. Example: input <?xml version="1.0" encoding="utf-8"?> <File> <Detail type="A" group="1" > <Data> <Nr>1</Nr> </Data> <Data> <Nr>2</Nr> </Data> </Detail> <Detail type="B" group="1"> <Data> <Nr>3</Nr> </Data> <Data> <Nr>4</Nr> </Data> </Detail>

xslt-1.0 iterate over fixed list of values

假如想象 提交于 2021-01-27 14:22:17
问题 I need to generate an XML structure for a fixed number of languages from an input that may or may not contain information for each language. If the information is missing, I need to generate empty elements. The problem is, that I need to iterate over the languages at many places in the output structure. The easiest way would be to use something resembling <xsl:variable name="languages" select="en,de,fr"> <xsl:for-each select="$languages"> ... </xsl:for-each> with the loop appearing wherever I

How to prevent self closing tags as well empty tags after transforming

余生长醉 提交于 2021-01-27 13:39:24
问题 I have in an input file: <a></a> <b/> <c>text</c> I need to converting this to string. Using transformer I am getting below output: <a/> <!-- Empty tags should not collapse--> <b/> <c>text</c> If I use xslt and output method is "HTML", I get the below output: <a></a> <!-- This is as expected--> <b></b> <!-- This is not expected--> <c>text</c> I want the structure same as in input file. It is required in my application since I need to calculate index and it will be very difficult to change the

XSLT 3.0 Dynamic select with variable in apply-templates?

浪子不回头ぞ 提交于 2021-01-27 12:09:02
问题 I want to apply templates to a set of nodes where part of the select path is a variable. I'm using Saxon-HE 9.8 (awesome lib!) I'm trying to achieve the following <variable name="x" select="string('baz')"/> <xsl:apply-templates select="foo/bar/$x"/> This doesn't seem to work. Is there a syntax that will allow me to dynamically construct the select XPath for this apply-templates instruction? Or, is there another technique for dynamically achieving this effect? I even tried pushing this down to

How to use XSLT 3.0 using Saxon-HE 9.8 in .NET

拜拜、爱过 提交于 2021-01-27 07:04:03
问题 I'm using Win7 and set my VSC# project to .NETFramework4. Then download SaxonHE9-8-0-7N-setup.exe and install. Then reference saxon9he-api.dll to C# project and using Saxon.Api; And here's my program.cs : static void Main(string[] args) { var xslt = new FileInfo(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory.ToString(), @"..\..\..")) + @"\TEST.xslt"); var input = new FileInfo(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory.ToString(), @"..\..\..")) + @"\TEST.xml"); var

Calling scala code in pyspark for XSLT transformations

ぃ、小莉子 提交于 2021-01-27 02:48:17
问题 This might be a long shot, but figured it couldn't hurt to ask. I'm attempting to use Elsevier's open-sourced spark-xml-utils package in pyspark to transform some XML records with XSLT. I've had a bit of success with some exploratory code getting a transformation to work: # open XSLT processor from spark's jvm context with open('/tmp/foo.xsl', 'r') as f: proc = sc._jvm.com.elsevier.spark_xml_utils.xslt.XSLTProcessor.getInstance(f.read()) # transform XML record with 'proc' with open('/tmp/bar