Menu
  • HOME
  • TAGS

How to move an attribute and its value from one element to another

xml,xslt,attributes,xslt-1.0

You need to think of this as two separate changes, rather than a single "move" 1) Remove the Weight attribute for the Order element. Or rather, do not copy the Weight attribute to the output <xsl:template match="@Weight" /> 2) Add a Weight attribute to the Item element when copying it...

XSLT processing with jaxb for a small transformation performance

java,performance,jaxb,xslt-1.0

From the performance perspective, of course it is not optimal: serialization to xml, transformation of the xml, deserialzation from the xml are costly operations. But, it sometimes makes sense, if you have a lot of 'similar' classes (for example different field names but matching logic (for example one having user...

How to print element tags in XML document using XSL

xml,xslt,xslt-1.0,xslt-2.0

Strictly speaking, you actually be getting an error when you run the output, as because MathiasMuller says in comments, xsl:element must not be a top-level element (i.e it cannot be a direct child of xsl;stylesheet). I am guessing Ecplise may just be ignoring that. If you are, however, getting only...

How to remove xml tags only using xslt

xml,xslt,xslt-1.0,xslt-2.0

You can use this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="p"> <xsl:copy> <xsl:value-of select="normalize-space(.)"/> </xsl:copy> </xsl:template> </xsl:stylesheet> ...

XSLT : storing accumulated values in array like structures

xml,xslt,xslt-1.0

It was quite challenging.... Here's my XSLT; please note that your XSL processor must support XSLT extensions (exslt) -- if you're using Xalan or Saxon, it will be OK. Basically, we had to process the Container one after another, and adding information about the Totals already computed. This is done...

Changing field name in XML file using XSLT

xml,xslt-1.0

How about a simple: <xsl:template match="/AUTHENTICATOR"> <xsl:copy> <xsl:copy-of select="LOGINID | DATE | USERTOKEN"/> <USERINFO> <field name="FirstName" value="{USERINFO/field[@name='First']/@value}"/> <field name="LastName" value="{USERINFO/field[@name='Last']/@value}"/> <field name="Email" value="{USERINFO/field[@name='mail']/@value}"/> </USERINFO> </xsl:copy> </xsl:template> ...

What is best XSLT XPath performance in my scenario?

xml,performance,xslt,xpath,xslt-1.0

The only possible answer to this question is "it depends on the processor". As a rule you should avoid using // un-necessarily, but a clever processor may be able to optimise simple //something absolute paths (e.g. using a hash table to look up nodes by name) to be faster than...

XSL XML transformation, changing namespace value

java,xslt,namespaces,xslt-1.0,saxon

The problem here is that you are changing the namespace on pref:sub1, but not on any of the other pref: elements. You need something more general: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:oldPref="http://www.myMountain.org/blabla" xmlns:pref="http://www.myHill.org/blabla" exclude-result-prefixes="oldPref"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="oldPref:*">...

How to use inline conditional (if then else) in XSLT?

xslt,sharepoint,sharepoint-2010,xslt-1.0,dataviewwebpart

As mentioned in the comments, the if () then else construct is only supported in XSLT/XPpath 2.0. My own preference would be to use the verbose, but readable: <xsl:template match="some-node"> <div> <xsl:attribute name="ID"> <xsl:choose> <xsl:when test="string(@ID)"> <xsl:value-of select="@ID"/> </xsl:when> <xsl:otherwise>default</xsl:otherwise> </xsl:choose> </xsl:attribute> </div> </xsl:template> or perhaps a shorter: <xsl:template match="some-node">...

XSLT muenchian grouping with the help of key

xml,xslt,xslt-1.0

If you are combining Document elements with the same language within a single Query, then you probably only need one key here <xsl:key name="Document" match="Document" use="concat(../../ID, '+', Language)"/> Then you get the distinct Document elements like so: <xsl:template match="Document[generate-id() = generate-id(key('Document', concat(../../ID, '+', Language))[1])]"> Then, for each child node of...

XSLT Issue trouble

xml,xslt,xslt-1.0

One thing I would like to apply is following: If Status in the account_data is = 5 then take the account id in the same line. I believe you mean: <xsl:value-of select="/notification/data/admin/input/request_set/request/update/account_data[@Status='5']/@id"/> This will return the id of the (first) account_data whose Status is 5 ("3615734" in your example)....

Why is substring-before() not working for me in XSLT?

xml,string,xslt,xslt-1.0

but the result of the third message is blank. The result is blank, because: str:split($A,$fileDateSplitChar)[last()] returns "xml", and: substring-before('xml, 'xml')" returns an empty string. What I was trying to achieve is to extract the part of the file CCYYMMDD. I am assuming you don't know the ordinal position of...

cutting the initial string dynamically in xslt

xslt,xslt-1.0

You can easily achieve this with a substring. <xsl:value-of select="substring-after(string(../fpml:floatingRateIndex), '-')"/> This will return everything after the first -....

Complex Grouping using XSLT 1.0

xml,xslt-1.0

If you want to have only unique Scott values within each Group, and only unique Minor values within each Scott subgroup, then yes, you will need three keys. And if the values by which you want to subgroup are not unique to each parent group, then the keys will have...

Namespace removal for modified element in XSL

xml,xslt-1.0,xml-namespaces

It's quite hard to follow your question, and there seems to be some typos in your XML, XSL, but here goes... I assume your XML input document that you are trying to translate is: <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <MyRequest> <ns:Details xmlns:ns="www.newschema"> <ID>123</ID> <Name> <FirstName>John</FirstName> </Name> </ns:Details> </MyRequest> </soapenv:Body>...

Testing conditions in XSLT with xsl:when

xslt,xslt-1.0

This is exactly the same situation as in your previous question - you're comparing against the (non-empty) string ' ' containing a single space, when what you actually want is to check for empty strings. And you can use the same solution as I suggested for that question, and test...

HTML output not as expected

xml,xslt-1.0

First of all, your xml and xslt files have 2 issues (as several commentors have pointed out): (xml): The & needs to be encoded: &#x26;. (xslt): Attribute names mustn't contain whitespace ( exclude-result-prefixes="msxsl" in the root element ) Back to the problem at hand: One of the default templates seems...

xslt grouping and removing duplicates

xml,xslt,xslt-1.0,xslt-grouping,muenchian-grouping

I think your code does correctly group the item elements by their name child elements. You also seem to want to eliminate duplicate child elements, I am not sure whether you want to do that by element name only or by element name and element contents. If you want to...

update the empty elements with some default value

xml,xslt,xslt-1.0

If you make your second template: <xsl:template match="*[not (node() or self::ty or self::mt_in)]"> <xsl:copy> <xsl:value-of select="'NO'"/> </xsl:copy> </xsl:template> you will get the following result: <?xml version="1.0" encoding="UTF-8"?> <request> <event> <st1>ky</st1> <st2>de</st2> <st3>NO</st3> <st4>NO</st4> <st5>NO</st5> <ty> <st_in> <stno>1</stno> <stid>NO</stid> </st_in>...

XSLT sort by attribute and attribute value (with exclude)

sorting,xslt,attributes,xslt-1.0,alphabetical

I am not entirely sure if this meets your requirements, but you could explicitly select the ones you want to come first in a separate xsl:apply-templates, then select the others with a sort on their type attribute <xsl:apply-templates select="orderEntry[@type='specific' or @type='other']" /> <xsl:apply-templates select="orderEntry[@type!='specific' and @type!='other']"> <xsl:sort select="@type" order="descending" />...

Iterate through siblings until a specific element type

xslt,xslt-1.0

One way to achieve this to use a key, to group the non-header elements by their first preceding header element <xsl:key name="type" match="*[not(self::header)]" use="generate-id(preceding-sibling::header[1])" /> You would then start off by selecting just header elements <xsl:apply-templates select="header" /> And within the template that matches this header element, you can then...

How to get repeated element from For-Each in XSLT 2.0

xml,xslt,xslt-1.0,xslt-2.0

Try it this way? <xsl:template match="/Data"> <Imdb> <xsl:for-each select="Movie"> <Film> <xsl:copy-of select="writer"/> </Film> </xsl:for-each> </Imdb> </xsl:template> I don't know what you mean by: I need to achieve the above mentioned task only with for each loop or for each group by loop. Surely you want to achieve the above task...

How do I create recursive template in xslt

xslt,recursion,xslt-1.0

I know nothing about SharePoint, I can only help you with the XSLT part. Once you have an XML document such as: XML <root> <Item> <Name>Test1</Name> <ID>1</ID> <ParentID>0</ParentID> </Item> <Item> <Name>Test2</Name> <ID>2</ID> <ParentID>0</ParentID> </Item> <Item> <Name>Test2.1</Name> <ID>3</ID> <ParentID>2</ParentID> </Item> <Item> <Name>Test2.1.1</Name>...

How to add one extra row to the table using XSLT?

asp.net,xslt,xslt-1.0

You want to check if you are a last <Item>, if so then add the invisible row. <xsl:if test="not(following-sibling::Item)"> <tr class="tdNewDesign" style="display: none;"> <td>A</td> <td>B</td> <td>C</td> <td>D</td> </tr> </xsl:if> ...

xslt select a node value based on the value of another node

xslt,xslt-1.0

Your test always returns true, because you are comparing two node-sets - and such test returns true if one of the nodes in set A matches a node in set B. The result is always "CONCENTRATE" because <xsl:value-of select="//i:materials/i:material/i:name"/> returns the value of the first node of the set matching...

Remove Duplicates from a list XSLT 1.0 based on element value

xslt-1.0

@lingamurthy, Just <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:strip-space elements="*"/> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="Code[. = preceding-sibling::Code]"/> </xsl:stylesheet> ...

Split Coordinates in XSLT

xml,xslt,xslt-1.0

As Ian commented, substring-before and substring-after can handle this for you: This XML: <coordinates>-3.166610, 51.461231</coordinates> Given to this XSLT transformation: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="coordinates"> <xsl:copy> <latitude> <xsl:value-of select="normalize-space(substring-before(., ','))"/> </latitude>...

How to get rid of the '\n' character while reading string from xsl?

java,xslt,xslt-1.0,xsl-fo

Did you try with : replaceAll("\\n","") And escapeJava() is not what you need, you need is unescapeJava() but like it says in the javadoc : Unescapes any Java literals found in the String. For example, it will turn a sequence of '\' and 'n' into a newline character, unless the...

Unkown system function: format-date in XSLT

xslt,xml-parsing,xslt-1.0,xslt-2.0

As per the error, it looks like you are using unsupported version of validation engine. Please choose Saxon-HE/PE/EE 9.5.1.7 instead of Saxon6.5.5 If you are using eclipse or Oxygen editor, you can find this settings under preferences > XML > XSLT-FO-XQuery. In Oxygen editor, you can choose engine from drop-down...

Formatting table columns to ignore duplicates XSLT-1.0

xslt,xslt-1.0,xsl-fo

It could be done with grouping, it can also be done with preceding-sibling. I would note that you say "dozens" ... I would not worry about using grouping. I ran this sample with 2000 rows, execution is 2.3 seconds (in debugging mode in oXygen with Saxon), 0.1 seconds without debugging....

XSL cannot parse with Firefox

css,xml,xslt,xslt-1.0

There is no xsl:value in XSLT. The instruction is called xsl:value-of. Stylesheet <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table border="1"> <tr> <th>Ime</th> <th>Grad</th> </tr> <xsl:for-each select="forma/unos"> <tr> <th> <xsl:value-of select="ime"/> </th> <th> <xsl:value-of select="grad"/> </th>...

XSLT parsing our more data than I'm selecting

xml,xslt,xslt-1.0

This is because of XSLT's built-in template rules. Since you're using xsl:value-of in your e:cd template you can just add this template: <xsl:template match="text()"/> Another alternative is to narrow the scope of what you're processing: <xsl:template match="/"> <xsl:apply-templates select="e:root/e:cds"/> </xsl:template> Also, unless you're creating an element name dynamically, there's no...

XSLT Transforming XML into a cross referenced, nested HTML lists when source nodes are siblings and nesting is based on attribute values

html,xml,xslt,transform,xslt-1.0

This is a classic case for using keys: XSLT 1.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> <xsl:key name="allowed-link" match="allowedlinks/link" use="@name" /> <xsl:key name="link-by-parent" match="link" use="@parent" /> <xsl:template match="/content"> <ul> <xsl:apply-templates select="data/navigation/link[not(@parent) and key('allowed-link', @name)]"/>...

Replace inner text of sibling of node having some inner text using XSLT

xml,xslt,xslt-1.0

Try: <xsl:template match="class[id='123']/duration"> <xsl:copy> <xsl:text>abc</xsl:text> </xsl:copy> </xsl:template> or: <xsl:template match="duration[../id='123']"> <xsl:copy> <xsl:text>abc</xsl:text> </xsl:copy> </xsl:template> instead of: <xsl:template match="id[text()='123']"> <xsl:copy> <xsl:if test="count(following-sibling::duration) or count(preceding-sibling::duration)"> <xsl:text>abc</xsl:text> </xsl:if>...

Opening my XML that references a XSL opens everything in a line

xml,xslt,xslt-1.0

The collapsible tree format is simply the way a browser displays XML files that don't have any stylesheet associated with them. When you ask a browser to apply a stylesheet the browser (quite rightly) assumes that the purpose of the stylesheet is to transform the input XML into something that...

How to retrieve max value with xsl:sort

xml,xslt-1.0

As stated in the comments for other members, max simply could be used as is without the need of xslt sort and xslt for-each. To be able to use the xsl in xsl as is, here is a simple piece of code to try: <xsl:variable name="the_max"> <xsl:for-each select="Node/Item/year"> <xsl:sort data-type="number"...

XSLT 1.0 select elements in Quiz XML

xml,xslt,xml-parsing,xslt-1.0

If it can be assumed that the Root element always contains exactly 2 Story elements, one with the Q&As and one with the correct answers, then you could do simply: XSLT 1.0 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.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="*"/> <!-- identity transform --> <xsl:template...

xslt sum node values where node value

xslt,xslt-1.0

You can try this way : <xsl:value-of select="sum(../i:issue[i:issueBatchNumber=$thisBatchId]/i:dispenseDurationInSeconds)"> above xpath return sum of all dispenseDurationInSeconds from parent issue elements having child issueBatchNumber equals current $thisBatchId value....

Using basename to name output file in java

java,find,xslt-1.0,filenames,zsh

Here's a zsh approach, since it's tagged it as such. for f in **/*.foo(.); print -- java ... -o $f:r.bar $f Remove the print -- when you're satisfied that it looks good. The (.) says files only. The :r says remove the .foo extension. It's helpful to remember the path...

Obtaining Previous element in xslt 1.0 sort order, not dom order

xml,xslt,xslt-1.0

You can sort first into a variable (which then in XSLT is a result tree fragment), then you can use an extension function like exsl:node-set to convert your result tree fragment into a node-set to be processed further with your existing code. So you need two changes, the template for...

Copy only the nodes where the name contains “a”

xml,xslt-1.0

Here's a small stylesheet that will lead you to the expected result. <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*[contains(name(), 'a')]/*[contains(name(), 'a')] | /*[contains(name(), 'a')]"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates /> </xsl:copy> </xsl:template> <xsl:template match="*"> </xsl:template> </xsl:stylesheet> However I think it's not really clearly stated for the...

How to apply two templates and group the result by size and used template with xslt

xml,xslt,xslt-1.0,nokogiri

Lets make this generic - we want $rows rows of $cols cards each per page, and on the answer side each row needs to be printed in reverse order. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="rows" select="2" /> <xsl:param name="cols" select="2" /> <xsl:variable name="pageSize" select="$rows * $cols" /> <xsl:template match="/"> <html> <body>...

XSL: Search for an element having an attribute equals to one property of the current attribute

xml,xslt,xslt-1.0

Perhaps it would be better to use a key for this, especially if there are many different RandomNode elements that you want to use for the lookup. Also, no need for named templates or parameters. XSLT Stylesheet The template match for Item can of course be changed to match="*[@Type='SomeUniqueType']" if...

Unique xml node

xslt,xml-parsing,xslt-1.0

Your question does not show any effort whatsoever, and you do not show any code you might have attempted already. However, I am feeling generous today, use the stylesheet below. XSLT Stylesheet As suggested by Michael already, use Muenchian grouping to identify unique nodes. Define a key that finds unique...

Check attribute value of XML element with a regular expression pattern

xpath,xslt-1.0

The matches function requires XPath 2.0 (and hence XSLT 2.0) or later, there's no regular expression support in XSLT 1.0. If you just want to check that the value ends with ".mov" you can do that using the substring function substring(@data, string-length(@data) - 3) = '.mov' (XPath 1.0 has starts-with...

How to calculate max string-length of a node-set?

xml,xslt,xslt-1.0,libxslt

<xsl:variable name="max_a_width"> <xsl:for-each select="data"> <xsl:sort select="string-length(@a)" data-type="number" /> <xsl:if test="position() = last()"> <xsl:value-of select="string-length(@a)" /> </xsl:if> </xsl:for-each> </xsl:variable> This is the general method of picking from an ordered list of derived values in XSLT 1.0. If you want to pick the minimum/maximum from actual (natively sortable) values, you can take...

XPath: how to select node that have a sibling containing text?

xpath,xslt-1.0,siblings

At this time I use xsl:template with match=w:tr[contains(.//w:t,'dataIdentifier')] Try instead: <xsl:template match="w:tr[.//w:t[contains(., 'dataIdentifier')]]"> -- Note: if the full path to w:t is known, it would be better to state it explicitly: <xsl:template match="w:tr[w:tc/w:p/w:r/w:t[contains(., 'dataIdentifier')]]"> ...

How to remove Multiple tags if present

xml,xslt,xslt-1.0

Muenchian grouping, i.e. (Just typed in without syntax checking, but should sthg. like this.) create a compound index for CIFContactReference, sth. like (I used to add a foreign character, say '_', for separation of keys, when no. and id are variable length and merge may be duplicated.) then make a...

XSLT Muenchian sorting

xslt,svg,xslt-1.0,muenchian-grouping

You've got the Muenchian grouping logic right, but the template wrong - your apply-templates selects product elements: <xsl:apply-templates select="order/product[generate-id(.)=generate-id(key('group-by-product',.)[1])]" /> but your second template matches order elements so it will never fire. You need to change it to something like <xsl:template match="product"> <xsl:variable name="y" select="sum(key('order-by-product',.)/@amount)"/> <svg:rect x="{40 * position()+20}" y="{$baseline...

How do I split string of values in XSLT1.0?

xslt,xslt-1.0

I don't want the result in form of XML nodes, I do want the result on the same line. If you want to sort the values, you must tokenize them into nodes first. Then sort the nodes and output them back as text values in a single line: XSLT...

XSL group by multiple conditions

xml,xslt,xslt-1.0

I would define the first key as <xsl:key name="key_group_by_master" match="root/*" use="id_master"/> and the second then needs to concatenate the master key with the slave key e.g. <xsl:key name="slave" match="root/*" use="concat(id_master, '|', id_x | id_y)"/> the inner for-each then needs to be <xsl:for-each select="//*[generate-id(.)=generate-id(key('slave', concat(id_master, '|', id_x | id_y))[1])]"> That should...

XSLT copy elements from second XML if an attribute is set in the first XML

xml,xslt,xslt-1.0

You could change line #10 from: <xsl:for-each select="*"> to: <xsl:for-each select="*[not(@override='false')]"> You didn't post the expected result, so I am not sure it will be to your liking. This could prove much more complicated than it seems, if you need to merge nodes at different levels....

Summing based on matching values XSLT-1.0

xslt,xslt-1.0,xsl-fo

This is so much easier in XSLT 2 but for old time's sake: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:key name="producerkey" match="row" use="PRODUCER/@value"/> <xsl:template match="table"> <table> <thead> <tr> <th>Producer</th> <th>Publication</th> <th>Domestic</th> <th>Foreigh</th> </tr> </thead> <tbody> <xsl:for-each select="row[ generate-id(.) =...

Memory efficient XSLT for transforming large XML files

xml,xslt,out-of-memory,xslt-1.0,xslt-2.0

Lingamurthy CS, Please, add the <xsl:strip-space elements="*"/> declaration, which you removed from the original solution. This strips from the source XML document any whitespace-only text node. Not stripping these nodes may significantly increase the number of nodes and the memory to hold them -- in your case, the required memory...

How to rename generic XML elements using the elements of a header node

xml,xslt,xslt-1.0

This should work for you, provided that the supplied column names are also valid XML element names: XSLT 1.0 <xsl:stylesheet version="1.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:variable name="column-names" select="/SearchResults/TableHeader/ColumnName" /> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/>...

Extracting multiple substrings from a string in XSLT 1.0

xml,string,xslt,substring,xslt-1.0

We do not know where this string comes from, but assuming an input document like XML Input <?xml version="1.0" encoding="UTF-8"?> <input>man START red END woman START child END rabbit START goose END blue</input> XSLT Stylesheet Write a recursive named template that looks for occurrences of START and END in the...

Add parent node to gather several children nodes using XSLT

xslt-1.0

Here's one way: XSLT 1.0 <xsl:stylesheet version="1.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="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="collectionDetails"> <xsl:copy> <xsl:apply-templates...

Pass absolute file path from java code to xslt document()

java,xml,xslt,jaxb,xslt-1.0

You need to construct a string then with the complete file URL: document(concat('file://', $mypath, '/myfile.xml')).

xslt transform using second xml document

xslt-1.0

Given these two XML documents: facilities.xml <facilities> <facility code="North">North Building</facility> <facility code="South">South Building</facility> </facilities> XML (this is the document processed by XSLT) <Dailyreport> <msg> <msgdate>05/27/2015</msgdate> <facility>North</facility> <ispass>1</ispass> </msg> <msg> <msgdate>05/27/2015</msgdate> <facility>North</facility>...

How to get xml Nodes which are in lower case using XSLT 1.0

xml,xslt,xpath,xslt-1.0

All you need is the identity template to copy existing nodes... <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> Then another template to ignore nodes that aren't lower-case. In XSLT 1.0 this can be done by using the translate statement, to translate uppercase letters to lowercase, and checking if the result...

Constructing, not selecting, XSL node set variable

xslt,xslt-1.0,msxsl

There isn't a "way around it" in XSLT 1.0 - it's exactly how this is supposed to work. When you have a variable that is declared with content rather than with a select then that content is a result tree fragment consisting of newly-created nodes (even if those nodes are...

Greater than(>) and less than(<) operator not working in XSLT

xml,xslt-1.0,ibm-datapower

I figured out where I went wrong. Below is the correct way to write the condition. I had put unnecessary single quotes. <xsl:when test="$IncomingFileSize &gt; $SetFileSize"> ...

Count unique values in comma separated value in xslt 1.0

xpath,xslt-1.0

It's possible without nodesets. It's not optimal, of course (hello, Shlemiel The Painter), but it's pretty easy - increment counter only if there is no given string ahead or behind. Template <xsl:template name="calcUnique"> <xsl:param name="str"/> <xsl:param name="back"/> <xsl:param name="count"/> <xsl:if test="$str"> <xsl:choose> <xsl:when test="contains($str, ',')"> <xsl:variable name="part" select="substring-before($str, ',')"/> <xsl:call-template...

xslt 1.0 consolidate empty element names

xml,xslt,xslt-1.0

This transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="EmptyElements" priority="5"> <xsl:copy> <xsl:apply-templates mode="enumerate" select= "../*[not(self::EmptyElements) and not(node())]" />...

XML/XSLT attribute output

xml,xslt,xslt-1.0

The problem you're having is with your xpaths. Your context is client so all paths have to be relative to that. So if you're trying to get the amount attribute of a child transaction, the xpath would be transaction/@amount. However, if you use <xsl:value-of select="transaction/@amount"/> and there are more than...

Xslt sorting nested nodes before parent by custom string values

xml,sorting,xslt,xslt-1.0

If I am guessing (!) correctly, you want to do: <xsl:apply-templates select="DriverRights"> <xsl:sort data-type="number" order="descending" select="4*(STAFF/EmpDetails/Type='Lorry ABC') + 2*(STAFF/EmpDetails/Type='SUV IX') + (STAFF/EmpDetails/Type='Jeep')"/> </xsl:apply-templates> ...

Remove repeated string in xslt

xml,xslt,xslt-1.0,xslt-2.0

Here is an XSLT 1.0 stylesheet adapted to your latest sample where the elements to be grouped are a nesting level further down the tree: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/> <xsl:key name="group" match="/*/*/*/property" use="@name"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy>...

XSLT 1.0: find the maximum value from given date and time

xml,xslt,xslt-1.0

XSLT 1.0 has no concept of dates (and even XSLT 2.0 only recognize dates in ISO-8601 format). So you need to do this in two steps: Convert your dates to a sortable string in the form of YYYMMDDhhmmss. This is further complicated by the necessity to convert 12-hour time to...

XSLT: Copy an attribute from one node to another

xml,xpath,xslt-1.0

You can modify the identity transformation to copy over everything exactly except for the visualChildren/object elements, which can be copied over as-is plus the RefId attribute you request: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template...

Adding a child attribute to the parent element in xslt 1.0

xml,xslt,xpath,xslt-1.0

It's difficult to provide an answer without seeing the input. I believe you need to do something like the following: XSLT 1.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="visualChildren"> <xsl:variable name="bundles"> <xsl:call-template name="create-bundles"> <xsl:with-param name="n" select="4" />...

xslt create ordered list from string

xml,xslt,xslt-1.0,xslt-2.0

It is possible but it would have to be a string operation, meaning it might not be possible in some cases if the text is more complex than this. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xs xd" version="2.0"> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="anons"> <ol> <xsl:for-each select="tokenize (./string(),...

How to remove attribute or replace attribute value using XSL/XSLT?

xml,xslt,xslt-1.0

I am trying to produce a xsl that will ... replace the attribute ref value with something hardcoded The main problem with your approach is that your second template is never applied, because your first template does not apply any templates. Try it this way: XSLT 1.0 <xsl:stylesheet version="1.0"...

How to transform xml data into rows and columns?

xml,xslt,xslt-1.0

Try it this way: <xsl:variable name="rows" select="2" /> <xsl:template match="/data"> <table> <xsl:for-each select="node[position() &lt;= $rows]"> <xsl:variable name="i" select="position() mod $rows"/> <tr> <xsl:for-each select="../node[position() mod $rows = $i]"> <td><xsl:value-of select="."/></td> </xsl:for-each> </tr> </xsl:for-each> </table> </xsl:template> ...

XSLT add not existing nodes

xslt,xslt-1.0

In this case since it's a straight sum you could just do <xsl:value-of select="sum(item[code=1.1 or code=1.2 or code=1.3.1 or code=1.3.2]/amt)"/> ...

how to sum up with recent date in xsl

xml,xslt,xslt-1.0

Try this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="item"> <xsl:if test="not(../item[nbr = current()/nbr and dt > current()/dt])"> <xsl:copy> <xsl:apply-templates /> </xsl:copy> </xsl:if> </xsl:template> <xsl:template match="cnt"> <xsl:copy> <xsl:value-of select="sum(../../item[nbr = current()/../nbr]/cnt)"/> </xsl:copy> </xsl:template> <xsl:template match="@* | node()">...

XSLT copy elements from second XML if not exist in the first XML

xml,xslt,xslt-1.0

That's a rather awkward arrangement to have, and the solution - at least in XSLT 1.0 - is no less awkward: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/car"> <xsl:variable name="local-names"> <xsl:for-each select="*"> <name><xsl:value-of...

Displaying output based on attribute value of xml tag

xml,xslt,xslt-1.0

I want to position them based on the attribute "num" value how do i do that?? This kind of manipulation is called sorting. Sorting the input elements inside xsl:apply-templates is what you need: <xsl:apply-templates select="name"> <xsl:sort select="@num"/> </xsl:apply-templates> Also, to avoid getting all the text on a single line,...

XSLT 1.0 pass to call-tempate a set of node names (analog of x in [a1, a2, a3])

xslt,xpath,xslt-1.0

<xsl:variable name="set" select="'(1.1)(1.2)(2.1)'"/> <xsl:template match="/"> <answer> <xsl:call-template name="sum-it"> <xsl:with-param name="set" select="$set"/> <xsl:with-param name="items" select="lines/item"/> </xsl:call-template> </answer> </xsl:template> <xsl:template name="sum-it"> <xsl:param name="set"/> <xsl:param name="items"/> <xsl:value-of select="sum( $items[contains($set,concat('(', code ,')'))]/amt)"/> </xsl:template> ...

How to split table after certain number of columns

xslt-1.0,xsl-fo

I couldn't understand your XSLT. To simplify the matter to the question of creating a separate table for every N lines, where each line forms a column, consider the following stylesheet: XSLT 1.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:variable name="col-limit" select="5" /> <xsl:variable name="rows" select="/Facture/Mensualite/Lines/Line[1]/*" /> <xsl:template...

Iterating through a returned node set in XSLT 1.0

xslt,xslt-1.0

how to now iterate through this returned node sets to add html styling to specific nodes Instead of: <xsl:otherwise> <xsl:copy-of select="$selected"/> </xsl:otherwise> you could do: <xsl:otherwise> <xsl:apply-templates select="$selected"/> </xsl:otherwise> then add templates matching the "specific nodes" you want to style. Hard to be more specific than that without seeing...

Compare two xmls and get the common nodes

xml,xslt,xpath,xslt-1.0

Use this XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:data="data"> <xsl:output method="xml" indent="yes"/> <xsl:variable name="xml2" select="document('xml2.xml')//item" /> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="item"> <xsl:variable name="item" select="$xml2[@name = current()/@name]"/> <xsl:if test="$item">...

How best to re-use XSLT code when different groups of documents have different optional tag attributes for the same tags?

xslt,xslt-1.0,xsl-fo

So, my original answer proved not to work because of the unfortunate way that <xsl:apply-imports/> works when there is no matching template. See the answer to this question for details. The bottom line is it resorts to default templates, which ends up messing the output when you use it the...

Nested grouping using XSLT muenchian-grouping

xslt-1.0,muenchian-grouping

And here goes the solution using Muenchian's grouping: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*"/> <xsl:output method="xml" indent="yes"/> <xsl:key name="group" match="property" use="@name"/> <xsl:template match="/EMailData/property/property | /EMailData/property/property/property/row"> <xsl:variable name="id" select="generate-id()"/> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:for-each...

How do I get a value from an xml file by using an xsl file - the files are in different directories

xml,xslt,xslt-1.0

Well XSLT uses URLs and not file paths so I would start with <xsl:variable name="file" select="'file:///C:/Test.xml'"/>. But these days chances are that security restrictions on local file system access hamper free navigation and access across it so make sure you check the error console whether it shows any messages.

How to extract domain name from url using xslt 1.0

xml,xslt,xslt-1.0

Googling around, I found the answer here: Extracting Domain from URL in XSLT <xsl:template match="/"> <xsl:variable name="url_ini" select="/root/url"/> <xsl:variable name="url_minus_http" select="substring-after($url_ini,'//')"/> <xsl:value-of select="substring-before($url_minus_http,'/')"/> </xsl:template> ...

XSLT every nth node with a filter

xml,xslt,xslt-1.0

You can use an outer loop with position() mod $num_per_div to get one "iteration" per chunk, then within that select out the members of that chunk out of the whole key(...) node set by their position: <xsl:for-each select="key('items-by-product', $productid) [position() mod $num_per_div = 1]"> <xsl:variable name="iter" select="position()" /> <xsl:variable name="first"...

XSLT effective sequence based on values

xml,xslt,xslt-1.0

This is a grouping problem, so you can use Muenchian grouping for this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:key name="kSequence" match="child" use="concat(name, '+', date)"/> <xsl:template match="/*"> <xsl:copy> <xsl:apply-templates select="child[generate-id() = generate-id(key('kSequence', concat(name, '+', date))[1])]" mode="group" /> </xsl:copy> </xsl:template> <xsl:template match="child"...

XSLT 'value-of select' on multiple attribute check at different level

xml,xslt,xslt-1.0

There were three mistakes here: You have elements named NameID, not Name (this was wrong in two places) @Class is an attribute on NameID, so you don't need a ../ before it. Once these are fixed, it works as expected: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <Detail>...

get node name from namespace

xslt,xslt-1.0

You can try using local-name(soapenv:Envelope/soapenv:Body/*), for example, the following XSL transformation : <xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:end="http://endpoint.ggg.com/" > <xsl:output method="text" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:element name="root"> <xsl:value-of select="local-name(soapenv:Envelope/soapenv:Body/*)"/> </xsl:element>...

Unanticipated behavior

xml,xslt,xslt-1.0,xsl-fo

I agree that the behaviour of apply-imports is difficult to understand. The problem is that apply-imports always finds a template that matches the current node, even if the user did not define it. In that case, the default template applies. The following stylesheet works: XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet...

Group and split Xmldocument on nth level descendant

xslt,xslt-1.0,muenchian-grouping

I think you can use Muenchian grouping to identify the first item in each group, then you need to recreate the tree for each group: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="group" match="RecordB11112" use="substring(Dates/StartDate, 1, 7)"/> <xsl:template match="/"> <Examples> <xsl:apply-templates select="//RecordB11112[generate-id() = generate-id(key('group',...