spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

rename and send all child nodes based on value of element in child node in xslt


You first need to start off with the XSLT identity template, which on its own copies all the nodes in the XML as-is

<xsl:template match="@*|node()">
   <xsl:copy>
      <xsl:apply-templates
select="@*|node()"/>
   </xsl:copy>
</xsl:template>

This means you only need to write templates for the nodes you wish to transform. You want to change Report_ID elements into Report_ID_Complicated where there is a Record with a name4 of false. This means you just have a template to match such a record

<xsl:template
match="Recordset/Report_ID[Record/name4 =
'false']">

Note the use of the preceding Recordset as there are nested Report_ID in the XML.

The contents would be similar to the identity template, except you can explicitly create a new node rather than copy the existing one

   <Report_ID_Complicated>
      <xsl:apply-templates
select="@*|node()"/>
   </Report_ID_Complicated>

For the other template, you could then match the opposite:

<xsl:template
match="Recordset/Report_ID[not(Record/name4 =
'false')]">

Note that it would not be correct to write a second template like this.

<xsl:template
match="Recordset/Report_ID">

This is because XSLT considers this to have the same priority as the previous one, which is an error, so you need the extra xpath condition to distinguish it. Also, note, if you had a template that matched just this...

<xsl:template match="Report_ID">

This would have a lower priority, which would be acceptable, but in the case of your XML, you have nested Report_ID elements which it would also match (Thanks to Lingamurthy CS for pointing this out!)

Try this XSLT

<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
match="Recordset/Report_ID[Record/name4 =
'false']">
      <Report_ID_Complicated>
         <xsl:apply-templates
select="@*|node()"/>
      </Report_ID_Complicated>
   </xsl:template>   

   <xsl:template
match="Recordset/Report_ID[not(Record/name4 =
'false')]">
      <Report_ID_Simple>
         <xsl:apply-templates
select="@*|node()"/>
      </Report_ID_Simple>
   </xsl:template>
</xsl:stylesheet>

Categories : Xml

Related to : rename and send all child nodes based on value of element in child node in xslt
How to loop through XML nodes and child nodes using JavaScript?
Attaching the root of your loop on employee rather than name would be better for nested loops (which is what this solution will use): var employees = xmlDoc.getElementsByTagName("employee"); //outputs array of employees for (employeeIndex = 0; employeeIndex < employees.length; employeeIndex++) { var empDetails = employees[employeeIndex].children; //outputs array of details for (deta

Categories : Javascript
VB.NET treeview error add second child nodes
hmm, You seem to get duplicate Keys. Try this: If mROC("parentCode").Value = "" Then srcTv.Nodes.Add(mROC("code").Value & "A", tmpStr) Else Dim TNode() As TreeNode = srcTv.Nodes.Find(mROC("parentCode").Value & "A", True) Dim sKey As String = mROC("code").Value If srcTv.Nodes.Find(sKey & "A", True) Is Nothing Then

Categories : Vb.Net
What is the proper way to run each function for many child nodes?
Recursion is the only solution. You need to write a function that processes a "page": process each subpage inside the current page using recursion process each file inside the current page Each file is an object with one key; you need to add the new key and remove the old key using the delete operator. var o = { "main": [{ "title": "AAA", "hash": "a", "subpage":

Categories : Javascript
Getting the child of nodes of XML having attributes - Java
You can read elements inside any XML tag using below function. public class XmlFileReader{ public NodeList readXML(String filePath, String tagName, String subTagName, String tagAttr) { try { // Get XML file object. File fXmlFile = new File(filePath); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilde

Categories : Java
ASP.NET jstree checkbox get all selected nodes and child
In Jstree there are 2 classes which can be used to differentiate between the node checked and unchecked states. They are ‘jstree-checked’ and ‘jstree-unchecked’ respectively So in order to get all the nodes which are unchecked you can use the below logic var nodeCheckedCount= $('.jstree-unchecked').length; var Ids = ''; if (nodeCheckedCount= > 0) { for (i

Categories : Twitter
Recently Add
get array result with wsdl and complexType
Same xml element in different places
How to post XML data to plone view and return xml data to sender?
Should a REST service expose a XSD for XML responses?
Querying a log file with multiple XML objects
How to set sorter of a List in Controller in SAPUI5?
XSLT Creating repetitive elements from Complex XML with Field and Metadata ids
and in a xml element
XML Nodes to be inserted with XSLT into a second Stylesheet
wso2 esb smooks un/edifact 96a EDI to XML
A complex type without an element in XSD
Convert rows of spreadsheet to separate XML files
XSLT mapping with metadata and field tags with multiple repetitive elements
Scala - Getting the error scala.xml.NodeSeq
XSLT - get value of all nodes with the same name
XSLT string join error
How do I parse XML web service in Swift?
Creating a complexType from multiple complexTypes
XSL repeating the same value but counting the correct number of different values
trying to export a complex xml from excel 2013
vb.net XML For loop
Chrome 39 XML/XSLT Renders Blank Page
How to make a drop down menu using xslt and xml?
xslt tokenize() and "Not a node item" error
Perl dies on big XML file, using STDIN
How to use custom sorter in XML views
distinct-values, contains function failed
Xslt code for fetching name value basing on the id value given in input
Don´t preload images in XML (google maps API v3)
rename and send all child nodes based on value of element in child node in xslt
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.