xslt , XSLT for iTunes importer

XSLT for iTunes importer


Tag: xslt

I need to transform a given XML to another format. This is the source:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://apple.com/itunes/importer" version="film5.1">
    <title>Some movie title</title>

And this is the XSLT I tried:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:importer="http://apple.com/itunes/importer" version="1.0">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

 <xsl:template match="importer:package">

    <xsl:variable name="var-title">
        <xsl:apply-templates select="video/title"/>

    <Title><xsl:value-of select="$var-title"/></Title>



But the <title> from source XML is not selected. What did I do wrong?


The namespace applies to the descendants as well so change <xsl:apply-templates select="video/title"/> to <xsl:apply-templates select="importer:video/importer:title"/> to use a prefix as well.


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

I'm reading xsl file using XSLReader class, and one of the columns contains strings but sometimes this string have enter in the (\n), so when I read this and print it I'm printing the string with the \n: those are two addresses, the first one have enter in the xsl...

XML, XSL namespaces

I'm new to XML especially namespaces. I made all the documents and everything seems to work fine, but I don't know whether I'm really using namespaces (which is requirement). Except that my html file are not valid because off this: "Attribute xmlns:xsi not allowed here." and "Attribute xmlns:xslformatting not allowed...

XSLT filePath with document as variable

I try to use a variable in the filePath, but it isn't working: BodyPart filePath="C:\\FileOutEmail\\($vpDocNr).xml" content-type="" content-id="" content-disposition="" multipart-type="" I also tried with the whole path in a variable without results: BodyPart filePath='$bestand' content-type="" content-id="" content-disposition="" multipart-type="" Is this possible, what is the right syntax?...

XML to Word using custom paragraph styles and XSLT

I've got an XML file that contains mostly textual information (list of questions in Moodle XML format). I'd like to convert it to a document that can be opened by MS Word, but I'd like to maintain context (using paragraph styles) so I can convert it back to Moodle XML....

Convert XSL 2.0 count by current-group logic into XSL 1.0 logic

I'm a novice with XSL and am trying to summarize some XML data based on grouping of substrings of data. I've been trying to get my head around Muenchian grouping and counting but have not been able to get it to work. I took a look at the XSL 2.0...

XslCompiledTransform Transform Method Not Working

I have a below xslt file. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:gl-bus="http://www.xbrl.org/int/gl/bus/2006-10-25" xmlns:gl-cor="http://www.xbrl.org/int/gl/cor/2006-10-25" xmlns:gl-gen="http://www.xbrl.org/int/gl/gen/2006-10-25" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:link="http://www.xbrl.org/2003/linkbase"...

Web.config transform Insert as first child

When transforming the web.config, how do I insert a web.config node as the first child of the parent? So I have <configuration> <system.webServer> <rewrite> <rules> <rule name="Foo" stopProcessing="true"> ... </rule> <rule name="Bar" stopProcessing="true"> ... </rule> </rules> </rewrite> </system.webServer> </configuration> And I want to insert another rule as the first rule....

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

I am trying to use XSLT to turn an XML document into plain text tables for human consumption. I am using xsltproc, which only implements XSLT 1.0 (so max is from EXSLT actually). I tried the below, but the commented-out definition fails because string-length returns only a single value (the...

XSLT insert sibling if it doesn't exist - Not being rerunnable for some reason

I'm trying to add a sibling to an element only if it doesn't exist. Here's my XML: <?xml version='1.0' encoding='UTF-8'?> <domain xmlns="http://xmlns.oracle.com/weblogic/domain" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/security/xacml http://xmlns.oracle.com/weblogic/security/xacml/1.0/xacml.xsd http://xmlns.oracle.com/weblogic/security/providers/passwordvalidator...

HashMap iteration in XSLT 2.0

I have an HashMap object as part of my java model and when I convert it into XML, this is the result... <transaction> <claims> <remarksMap> <entry> <string>XX</string> <string>Description 1</string> </entry> <entry> <string>YYY</string> <string>Description 2</string> </entry> <entry> <string>ZZZZ</string> <string>Description 3</string> </entry> </remarksMap> </claims> </transaction> I would like to...

What match=“/” actually returns?

What exactly does match="/" returns if we assume we have XML shown below? As far as I can tell it returns some imaginary top level node which has <people> element as its child. What is the type of this node among those 7 types of nodes: element, attribute, text, namespace,...

XSLT to copy value in a node to another across repeating nodes

very new to XSLT and needs some help in transforming the XML. The below XML can have multiple "row" tags <?xml version="1.0" encoding="UTF-8"?> <ns1:row> <ns1:City>BALTIMORE</ns1:City> <ns1:Miscdata> <ns1:Building> <ns1:VendorCode>123</ns1:VendorCode> <ns1:Value>2</ns1:Value> </ns1:Building> <ns1:Building> <ns1:VendorCode>345</ns1:VendorCode> <ns1:Value>8</ns1:Value> </ns1:Building> </ns1:Miscdata> </ns1:row>...

removing a parent node dependig upon child node using xslt

i am looking forwar for an template that removes anode from xml depending upon the value of a chid node,basically i am having an xml like: <EventInfo> <AssignmentEvent> <CreateDateTime>2015-06-02T00:00:00+02:00</CreateDateTime> </AssignmentEvent> <EstimateEvent> <CreateDateTime>2015-06-02T07:38:28.0000000Z</CreateDateTime> <CommitDateTime>2015-06-04T14:29:38.0000000Z</CommitDateTime> <UploadDateTime>2015-06-04T14:29:39.7651796Z</UploadDateTime>...

XSLT remove data if attribute value is higher than threshold

I am newbie to XSLT. My am is to remove elements from XML based on a field if it is higher than some threshold value which I will be getting as parameter to it. My XML is as shown below: <tns:PM objectClass="MyNode" objectName="" className="com.project.converter.PMFamilyConverter" interfaceName="ComponentPM" xmlns:tns="http://www.myproject/SS/PMSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.myProject.com/SS/PM.xsd"> <tns:family desc="family0"...

Check the node is present or not in xslt

I am new to xslt, Though I manage to work on it. But I struck with one case for which I need a help from expert. I am trying to finding the node which is Exists or not. I already search this same question, in which I didn't get the...

Math operations in xsl template - XSLTranform geocoordinates from deg to meters

I haven't been able to make this work. I'm trying to make a template for an xsl tranformation of degrees geocoordinates to meters. The function in PHP is like this and works just fine: function degtometers($lon, $lat) { $half_circumference = 20037508.34; $x = round($lon * $half_circumference / 180); $y =...

XSLT sort by attribute and attribute value (with exclude)

I have a following XML code: <module> <component> <output> <output-test> <exclude-output/> <orderEntry type="specific"/> <orderEntry type="other"/> <orderEntry type="module" module-name="module1"/> <orderEntry type="module" module-name="module3"/> <orderEntry type="module" module-name="module2"/> <orderEntry type="library" name="library1"/> <orderEntry type="library" name="library3"/> <orderEntry type="module" module-name="module4"/> <orderEntry...

XSL - iterate through elements and update based on the node index from another xml file

I have an XML file with multiple Shape elements each with a child Material element that contains a Code attribute. I want to update the Code attribute for each Material element based on a value that is obtained from a separate XML file. The problem I have is that the...

XSL-FO table-cell with superscript and vertical alignment

This is the situation: I am converting html to xsl-fo to pdf. I am displaying a heading text like "4.4.1. [Header Text]" by use of a table, because it might happen that the [Header Text] is quite long and in that case shall wrap onto the next line like so:...

XSLT - Put Content by checking attribute

I'm new to XSLT. and I've a xml to xml transformation task. what I have to do is put some xml node to result xml tree by checking some attribute values in original xml file. example : original xml has <doc> <sec id="sec_1" sec-type="scope"> </sec> <sec id="sec_1" sec-type="norm-refs"> </sec> //more...

Difference between ancestor and ancestor-or-self

I know about ancestor in xpath but what is this ancestor-or-self. when we have to use ancestor-or-self.Please give me any examples.

Adding a child attribute to the parent element in xslt 1.0

I have multiple elements that contain an uniqueId(generated and stored in a variable). I have recursively added the element(object class=Bundle with unique id ) with the xsl as follows <xsl:template match="visualChildren"> <object class="Set" > <installChildren> <xsl:call-template name="Bundle"> <xsl:with-param name="i" select="1"/> <xsl:with-param name="limit" select="4" /> </xsl:call-template> </installChildren> </object> </xsl:template> <xsl:template name="Bundle">...

Transform XML structure using XSLT

I want to transform an XML structure with XSLT. <detaileddescription> <para>Some text</para> <para> <bold>Title</bold> </para> <para>Intro text: <itemizedlist> <listitem> <para>Text</para> </listitem> <listitem> <para>Text</para> </listitem> </itemizedlist> </para> </detaileddescription> This is what I want: <detaileddescription> <para>Some text</para> <List>...

XSLT How to remove style from div and td tags

I am new to XSLT. I got stuck while removing style attributes from div, td or li tags. Input XML: <?xml version="1.0" encoding="UTF-8"?> <div xmlns="http://www.w3.org/1999/xhtml"> <table style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; WIDTH: 606px; BORDER-COLLAPSE: collapse; WORD-WRAP: break-word; TABLE-LAYOUT: fixed; BORDER-TOP: medium none; BORDER-RIGHT: medium none" class="MsoNormalTable msoUcTable" tabIndex="-1" border="1"...

Selecting data in XSL from different sections of XML

I am new to XSLT. I have an XML- <root> <fiberList> <fiber> <A>abcd</A> <B>bcde</B> <C>cdef</C> </fiber> </fiberList> <generatorList> <generator> <D>defg</D> <E>efgh</E> </generator> </root> I want to transform this XML into another XML through XSL. The resulting XML should be something like this- <parent> <child> <M>abcd</M> <N>bcde</N> <O>efgh</O> </child> </parent> But...

XPath Recursive Descent behaves differently between match and select

Info Why is there different behaviour of Recursive Descent operator between ● template's match attribute where it is ignored and only children are selected ignoring their descendants ● for-each's select attribute where it works properly Two examples of test.xsl are given which both operate on the following test.xml. test.xml <?xml...

ProcessBuilder or Runtime.getRuntime().exec won't complete jar execution

I have a jar which converts one XML to other XML format using XSLT in Java. The jar copies the output to some folder. It is working absolutely fine when am running it on command prompt but running it via Runtime.getRuntime().exec or ProcessBuilder, doesn't complete the process. Just 25 files...

Using XSLT variable in X PATH string

I have an XPath string as follows: /results/server[@name='server1'] I would like to construct a new XPath using a previously defined XSLT variable: /results/server[@name='$server'] I haven't tried 'concat' might be possible with that. I am using XSLT 2.0. XSLT parser complains if I use the string as defined above: XPST0003 XPath...

xslt condition output one by one

hope that someone has a suggestion about this: I need to have in each 'a', all the 'b' that have @n equal or bigger than the @n of the 'a' in which they are. I am using xslt 2.0 and Saxon-HE XML source: <blabla> <a n="2"></a> <a n="6"></a> <b...

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

I need to get XML nodes which are in lower case and values of it using XSLT 1.0 and display the output as XML <main> <ACAT>Cat Name A </ACAT> <bcat>Cat Name b </bcat> <ccat>Cat Name c </ccat> <dcat>Cat Name d </dcat> <ECAT>Cat Name E </ECAT> <fcat>Cat Name f </fcat> </main>...

About sorting based on the counting of subelements

i have an xml document with properties that belong to agencies: <agency name="Century 42" num="Century42" mail="[email protected]"/> <property agency="Century42" ....> ... I would like to print the info of all agencies. The agencies should be sorted by the number of properties that they own. I tried this but it does not...

apply-templates based on attribute id value

My XML is as below <?xml version="1.0" encoding="UTF-8"?> <product> <admin id="1"> <name>abc</name> </admin> <admin id="2"> <name>kkk</name> </admin> <product> Here is my XSLT <xsl:template match="product"> <ul> <xsl:apply-templates select="admin"/> </ul> I want to apply templates on "admin" based on attribute id value. How to apply templates based on attribute value? New question......

XSL transformation outputting multiple times and other confusion

I'm attempting to transform a section of an XML document (which is mostly HTML) with a templated piece of markup should a particular pattern be matched. I'm inexperienced with XSLT (I've only used xpath, really) and online documentation is sparse so I'm struggling with it... To the following XML document:...

Split XML into multiple files using xslt on string length

I'm looking at trying to split an XML file into 2 separate files. They have to be split on the length of a string in a particular element. I've been attempting to use the <xsl:for-each-group> and <xsl:result-document> elements in order to do this but only get the 1st matching 'object'...

XSLT 1.0 - Multiple Child Nodes Formatted Output

I can do this with For-Each but having some problems with Apply_Templates. The XML Data contains varying child nodes but I want to display all child nodes with their parents information. <orders> <order> <customer>1</customer> <items> <item> <name>Widget A</name> <price>10</price> <code>1A</code> </item> </items> </order> <order> <customer>2</customer> <items> <item> <name>Widget A</name>...

Insert tag if and only if it does not exist

I would like to do an XSLT transformation on an XML file ensuring that tag <B> is inserted into tag <A> if and only if it is not there. Example: <A>foo</A> should become <A><B>foo</B></A> <A>foo <x>bar</x></A> should become <A><B>foo <x>bar</x></B></A> <A><B>foo</B></A> should remain <A><B>foo</B></A> <A><B>foo <x>bar</x></B></A> should remain...

XSLT get all nodes with text

I'm trying to loop through all nodes with text in my document from a certain location. <xsl:template name="interpret_text"> <xsl:param name="location"/> <xsl:for-each select="$location//text()"> <xsl:choose> <xsl:when test="name(.) = tag_im_looking_for"> <!-- various code stuff and closing tags --> This code is functional except you may notice my problem. When I enter the for-each...

Convert meters to foot in xml data via xsl transformation

I would like to modify my xml file by converting some values ([email protected]) from meter to foot. I am a newbie to xml and this should be no problem for one of you. The formular is: 1 meter are 3.2808 feet I want to convert the attribute value of node/[email protected]

XSLT Sequence Number Generation

I am preparing one flat file from XMl using XSLT 2.0. My input XML is <city> <family> <parent>A</parent> <child>A1</child> </family> <family> <parent>A</parent> <child>A2</child> </family> <family> <parent>B</parent> <child>B1</child> </family> <family> <parent>B</parent> <child>B2</child> </family> <family> <parent>B</parent> <child>B3</child>...

Summing based on matching values XSLT-1.0

I'm currently trying to work with grouping in XSLT 1.0. I have XML similar to this: <table> <row> <PRODUCER type="VARCHAR" value="PRODUCER 1"/> <PUBLICATION_CODE_-_NAME type="VARCHAR" value="PUBLICATION A"/> <DOMESTIC type="DECIMAL" value="20"/> <FOREIGN type="DECIMAL" value="4"/> </row> <row> <PRODUCER type="VARCHAR" value="PRODUCER 1"/> <PUBLICATION_CODE_-_NAME type="VARCHAR" value="PUBLICATION B"/> <DOMESTIC type="DECIMAL" value="57"/> <FOREIGN type="DECIMAL"...

XSLT for-each statement not iterating proper amount of times

I am having trouble with my XSLT for-each statements. When I run the XML through the XSLT, it only comes up with the first iteration of the list, and then stops. It doesn't post the values either. Here is the XML code. <?xml version="1.0" encoding="UTF-8"?> <template> <L> <Q>Hey</Q> <Q>There</Q> <Q>Thank...

XSL getting out of context using dynamic XPATH

I'm trying to reformat an XML I get from an appliance into an HTML table, and it's format is not usual. It use unique references in node name's, like this: /network/content/host/content/REF_1/content /network/content/network/content/REF_2/content and then, it use the same references to another part of the file, as a value of a...

How to XSLT transform XML nested attribute elements and concatenate name

I am not savvy with XML/XSLT at all. I'm just trying to learn enough to transform this XML file into something that my Access database can use. The XML data was output in an attribute format and Access only likes the element format. I have the basic transformations down, but...

Remove XML Node text using XSLT

I need to modify xml document with XSLT. what I need is to remove some node name from xml document. Example: <link ref="www.facebook.com"> <c type="Hyperlink">www.facebook.com<c> </link> I need to convert this xml as follows (remove the <c> node and attribute form xml), <link ref="www.facebook.com"> www.facebook.com </link> I tried to do...

group siblings by identifying the first node of a certain type in sequence

Not sure if that description is the best...but given this xml: <?xml version="1.0"?> <root> <type1 num="1" first="1"/> <type1 num="2" /> <type2 num="3" /> <type2 num="4" /> <type1 num="5" first="2"/> <type1 num="6" /> <type2 num="7" /> <type2 num="8" /> <type1 num="9" first="3"/> <type1 num="10" /> <type2 num="11" /> <type2 num="12" />...

Transform XML to another XML using XSL based on some condition

I have an XML - <root> <gereratorList> <generator> <id>1</id> <A>123</A> </generator> <generator> <id>10</id> <A>456</A> </generator> <generator> <id>111</id> <A>789</A> </generator> </gereratorList> </root> I want to transform this XML into another XML through XSL. The resulting XML should be something like this - <parent> <child> <test>456</test> <child> </parent> But I am...

List unique values of an attribute within a group only for specific criteria in XSL 1.0

I need to list the unique values of an attribute in a group, when another attribute has a specific value. Making this work in XSL 1.0 is very tricky to understand. Thanks to another post, I now have the groupings defined to allow me to perform counts when attributes match...

XQuery XML insert

I have XML based target data: <myTargetData> <myMap> <pairs> <key>KEY_1</key> <value> <myMap> <pairs> <key>INNER_KEY_1</key> <value/> </pairs> <pairs> <key>INNER_KEY_2</key> <value/> </pairs> <pairs> <key>INNER_KEY_3</key> <value> <myMap> <pairs> <key>INNER_INNER_KEY_1</key> <value/> </pairs> <pairs> <key>INNER_INNER_KEY_2</key> <value/>...

Is it possible to preprocess xml source within the same XSLT Stylesheet?

Within the same XSLT (2.0) Stylesheet and transformation I would like to: 1) first preprocess the whole XML Datasource (Add a attribute with a specific calculation to certain elements) and then 2: transform the changed XML Datasource with the sylesheet's templates. How can I achieve this? A code example would...

XML-XSLT-XPATH : How to convert multiple XML elements to a string, separated by semicolon

I have just demonstrated my question as an input and output format as below. I have an input as xml document which consist of following data <Users> <user> <name>Mark Curtain</name> <email>[email protected]</email> <username>mark</username> </user> <user> <name>Zuke Gossip</name> <email>[email protected]</email> <username>zuke</username> </user> <user> <name>Villan Kiosk</name> <email>[email protected]</email>...