xslt-1.0

Randomize sorting in xslt 1.0?

≯℡__Kan透↙ 提交于 2020-02-06 09:02:54
问题 I would like to know, is there is any way to do random sorting in XSLT 1.0? Here is my XML <root><DO status="a">text comes here</DO><DO status="b">text comes here</DO><DO status="c">text comes here</DO><DO status="d">text comes here</DO><DO status="e">text comes here</DO></root> Desired Output: <root><DO status="c">text</DO><DO status="a">text comes here</DO><DO status="b">text comes here</DO><DO status="e">text comes here</DO><DO status="d">text comes here</DO></root> Hope my question is

How to select the smallest value from a bunch of variables?

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-03 05:20:07
问题 Assume I have variables $a , $b , $c and $d which all hold numbers. I would like to get the smallest (largest) value. My typical XSLT 1.0 approach to this is <xsl:variable name="minimum"> <xsl:for-each select="$a | $b | $c | $d"> <xsl:sort select="." data-type="number" order="ascending" /> <xsl:if test="position()=1"><xsl:value-of select="." /></xsl:if> </xsl:for-each> </xsl:variable> However, my xslt 1.0 processor complains with runtime error: file stylesheet.xslt line 106 element for-each

xslt 1.0 how to replace empty or blank value with 0 (zero) in select condition

孤街浪徒 提交于 2020-02-02 04:16:01
问题 <xsl:call-template name="SetNetTemplate"> <xsl:with-param name="xyz" select="$node1value + $node2value + $node3value - $node4value - $node5value - $node6value"/> </xsl:call-template> If nodevalue is empty or blank, i want to replace that value with 0 (zero). Problem is that in this calculation if any nodevalue is empty or blank, it is giving NaN result. e.g. select "10-2+5-2- -4" 回答1: Try it this way: <xsl:with-param name="xyz" select="translate(number($node1value), 'aN', '0') + translate

xslt 1.0 how to replace empty or blank value with 0 (zero) in select condition

独自空忆成欢 提交于 2020-02-02 04:14:10
问题 <xsl:call-template name="SetNetTemplate"> <xsl:with-param name="xyz" select="$node1value + $node2value + $node3value - $node4value - $node5value - $node6value"/> </xsl:call-template> If nodevalue is empty or blank, i want to replace that value with 0 (zero). Problem is that in this calculation if any nodevalue is empty or blank, it is giving NaN result. e.g. select "10-2+5-2- -4" 回答1: Try it this way: <xsl:with-param name="xyz" select="translate(number($node1value), 'aN', '0') + translate

how transform from xml to json with xsl and removing the item/record labels

北城以北 提交于 2020-01-25 18:48:33
问题 Thanks to the excellent answer provided by Tim C in how transform from xml based on attributes to json and ignore the attributes from especific elements by using XSLT/XSL, I could learn how to transform my input xml to a json and excluding the item attributes during transformation. Kindly, see the input xml file below. Please, how can I do exact same transformation but ignoring the "aa" and "bbb" in the output json? I mean, how do I exclude during xml transformation to json the record

Adding some new conditions to the XSLT-recursion

倖福魔咒の 提交于 2020-01-25 06:42:43
问题 Here is the existing XML-source and XSLT-transformation code which restores all parent-child interconnetion chain. The algorithm does the correct work, but need to take into account new additional conditions; plus output "string" (or names) values have to take more formalized, proper form. ======= base source <root> <document ID-1="galaxyID" ID-2="NULL" ID-3="111" SHORTNAME="gal" NAME="Milky Way"/> <!-- this is parent's node --> <document ID-1="starID" ID-2="galaxyID" ID-3="222" SHORTNAME="st

XSLT replacing text in attribute value and text nodes

时间秒杀一切 提交于 2020-01-25 04:26:13
问题 I have an XML document that I'm trying to transform and do a string replace of certain values when that value occurs in either a text node or an attribute named message . My xsl file is below, but the main issue is that when the replace occurs in the message attribute, it actually replaces the whole attribute and not just the value of that attribute, so <mynode message="hello, replaceThisText"></mynode> becomes <mynode>hello, withThisValue</mynode> Instead of <mynode message="hello,

XSLT replacing text in attribute value and text nodes

不羁岁月 提交于 2020-01-25 04:25:59
问题 I have an XML document that I'm trying to transform and do a string replace of certain values when that value occurs in either a text node or an attribute named message . My xsl file is below, but the main issue is that when the replace occurs in the message attribute, it actually replaces the whole attribute and not just the value of that attribute, so <mynode message="hello, replaceThisText"></mynode> becomes <mynode>hello, withThisValue</mynode> Instead of <mynode message="hello,

How to transform xml to requested one

空扰寡人 提交于 2020-01-25 03:33:09
问题 I have an xml which I must transform it to another structure of xml. I tried many ways but no success. I need to use xslt 1.0. I asked a question but the format is changed after I asked. input: <?xml version="1.0" encoding="ISO-8859-1"?> <PersonBody> <Person> <D>Name</D> <D>Surname</D> <D>Id</D> </Person> <PersonValues> <D>Michael</D> <D>Jackson</D> <D>01</D> </PersonValues> <PersonValues> <D>James</D> <D>Bond</D> <D>007</D> </PersonValues> <PersonValues> <D>Kobe</D> <D>Bryant</D> <D>24</D> <

How to add a delimiter between each element in a for-each loop?

扶醉桌前 提交于 2020-01-25 02:49:05
问题 I am looping through each element in a list and outputting a certain value: <xsl:for-each select="properties/property"> <xsl:value-of select="name"/> </xsl:for-each> This simply outputs a concatenation of the name node of property. I want to add delimiter, such as ; between each element. How can this be done? I listed XSLT versions 1.0, 2.0 and 3.0 as functionalities might differ between different versions. 回答1: If you are using XSLT 2.0 or above, you can drop the xsl:for-each and just do it