xslt

XPath recursive “parent”-selection in a flat structure

孤街醉人 提交于 2020-01-22 00:25:32
问题 The following XML is given: <root> <element> <id>1</id> </element> <element> <id>2</id> <parentId>1</parentId> </element> <element> <id>3</id> <parentId>2</parentId> </element> <element> <id>4</id> <parentId>3</parentId> </element> <element> <id>5</id> <parentId>2</parentId> </element> <element> <id>6</id> <parentId>5</parentId> </element> </root> Now, I want to select all "parent"-nodes for e.g. element 3. Let's say, the desired output for element 3 should be: element 1 element 2 The desired

XPath recursive “parent”-selection in a flat structure

六月ゝ 毕业季﹏ 提交于 2020-01-22 00:24:10
问题 The following XML is given: <root> <element> <id>1</id> </element> <element> <id>2</id> <parentId>1</parentId> </element> <element> <id>3</id> <parentId>2</parentId> </element> <element> <id>4</id> <parentId>3</parentId> </element> <element> <id>5</id> <parentId>2</parentId> </element> <element> <id>6</id> <parentId>5</parentId> </element> </root> Now, I want to select all "parent"-nodes for e.g. element 3. Let's say, the desired output for element 3 should be: element 1 element 2 The desired

How to access xsl:param in an attribute of xsl:output?

夙愿已清 提交于 2020-01-21 21:15:10
问题 I want to allow the transformer to set a param in my stylesheet to specify how many spaces of indentation are desired. I have tried all of the suggestions by @Dimitre Novatchev in the answer here to no avail. <xsl:param name="indent" select="0"/><!-- default indent is 0, but transformer could specify a different value --> <xsl:output indent="yes" method="xml" omit-xml-declaration="yes" xalan:indent-amount="{$indent}"/> <!-- This does not work --> How do I assign the value of the indent param

Input parameter in xslt

青春壹個敷衍的年華 提交于 2020-01-21 12:58:15
问题 How do I pass an input parameter to an XSLT stylesheet? I'm using xsltproc, and I'd like to use --stringparam <param> <value> as argument, but I don't know how to access the parameter inside the XSLT. Can someone give an example? Thanks in advance. 回答1: This is one I am using. The default value part is optional. You must have a <xsl:param name="yourParamname"/> . <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- default value --> <xsl

xslt 3.0 json-to-xml and xml-to-json conversion

吃可爱长大的小学妹 提交于 2020-01-21 03:49:26
问题 Currently I need to convert json to xml and xml to json vice versa using XSLT 3.0 & Saxon-HE. Below is my json abc.xml file <?xml version="1.0" encoding="UTF-8" ?> <root> <data>{ "cars" : [ {"doors" : "4","price" : "6L"}, {"doors" : "5","price" : "13L"} ] } </data> </root> Below is xsl file xyz.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs

Replacing strings in various XML files

烂漫一生 提交于 2020-01-20 08:31:52
问题 Given the following xml file with the knowledge that the structure and contents can change: <something> <parent> <child>Bird is the word 1.</child> <child>Curd is the word 2.</child> <child>Nerd is the word 3.</child> </parent> <parent> <child>Bird is the word 4.</child> <child>Word is the word 5.</child> <child>Bird is the word 6.</child> </parent> </something> I would like a way to use xquery (and even xslt) to replace all instances of a supplied string with another. For example, replace

How to filter a select nodeset with a PHP function?

南笙酒味 提交于 2020-01-20 04:37:32
问题 I wonder if and how it is possible to register a PHP userspace function with the XSLT processor that is able not only to take an array of nodes but also to return it? Right now PHP complains about an array to string conversion using the common setup: function all_but_first(array $nodes) { array_shift($nodes); shuffle($nodes); return $nodes; }; $proc = new XSLTProcessor(); $proc->registerPHPFunctions(); $proc->importStylesheet($xslDoc); $buffer = $proc->transformToXML($xmlDoc); The XMLDocument

Preserving attribute whitespace

会有一股神秘感。 提交于 2020-01-19 03:45:14
问题 Disclaimer: the following is a sin against XML. That's why I'm trying to change it with XSLT :) My XML currently looks like this: <root> <object name="blarg" property1="shablarg" property2="werg".../> <object name="yetanotherobject" .../> </root> Yes, I'm putting all the textual data in attributes. I'm hoping XSLT can save me; I want to move toward something like this: <root> <object> <name>blarg</name> <property1>shablarg</name> ... </object> <object> ... </object> </root> I've actually got

Turn XML data to HTML table with XSLT

微笑、不失礼 提交于 2020-01-17 14:44:08
问题 I need to be able to turn a flat xml data sets into html tables, and I'm having trouble finding syntax examples that will fit my need. I would like to use one stylesheet that can convert similar looking data sets into html tables with variable columns. this is a part of my XML File : <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="XSLT_StyleSheet.xsl"?> <Services> <Service WsdlUrl="http://venus.eas.asu.edu/WSRepository/Services/BasicThreeSvc/Service.svc"> <Name

Turn XML data to HTML table with XSLT

纵饮孤独 提交于 2020-01-17 14:44:07
问题 I need to be able to turn a flat xml data sets into html tables, and I'm having trouble finding syntax examples that will fit my need. I would like to use one stylesheet that can convert similar looking data sets into html tables with variable columns. this is a part of my XML File : <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="XSLT_StyleSheet.xsl"?> <Services> <Service WsdlUrl="http://venus.eas.asu.edu/WSRepository/Services/BasicThreeSvc/Service.svc"> <Name