logo
down
shadow

Re-arranging xml using xslt considering element attribute value


Re-arranging xml using xslt considering element attribute value

By : Gulbuddin Zahid
Date : November 22 2020, 11:05 AM
it should still fix some issue There are many ways to rearrange nodes in XSLT, from simple alphabetical or numerical sorting, to complex grouping. If you can use XSLT 2.0 or XSLT 1.0 with extensions, you can usually get away with in templates or loops and functions. If you are restricted to XSLT 1.0 you can do basic sorting in templates or loops on node-sets, but will have to write more complicated algorithms for grouping (ex: Muenchian method).
Using your simple example I thought of some ways to rearrange the nodes. Process your example with the stylesheet below and you will see some examples.
code :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:output indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <Results>
            <xsl:apply-templates select="Users" mode="sort-name-alphabetical-asc" />
            <xsl:apply-templates select="Users" mode="sort-division-alphabetical-desc" />
            <xsl:apply-templates select="Users" mode="sort-id-numerical-desc" />
            <xsl:apply-templates select="Users" mode="sort-by-number-of-chars-in-division" />
            <xsl:apply-templates select="Users" mode="sort-by-last-letter-in-name" />
        </Results>   
    </xsl:template>

    <xsl:template match="User">
        <xsl:copy-of select="." />
    </xsl:template>

    <xsl:template match="Users" mode="sort-name-alphabetical-asc">
        <example>Sort by name, alphabetical, ascending</example>
        <xsl:copy>
            <xsl:apply-templates select="User">
                <xsl:sort select="@name" data-type="text" />
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Users" mode="sort-division-alphabetical-desc">
        <example>Sort by Division, alphabetical, descending</example>
        <xsl:copy>
            <xsl:apply-templates select="User">
                <xsl:sort select="@Division" data-type="text" order="descending" />
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Users" mode="sort-id-numerical-desc">
        <example>Sort by id, numerical, descending</example>
        <xsl:copy>
            <xsl:apply-templates select="User">
                <xsl:sort select="@id" data-type="number" order="descending" />
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Users" mode="sort-by-number-of-chars-in-division">
        <example>Sort by number of total chars in Division + name</example>
        <xsl:copy>
            <xsl:apply-templates select="User">
                <xsl:sort select="string-length(@Division) + string-length(@name)" data-type="number" />
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Users" mode="sort-by-last-letter-in-name">
        <example>Sort by last letter in name</example>
        <xsl:copy>
            <xsl:apply-templates select="User">
                <!-- In XSLT 2.0 you can use node()[ends-with(@name, '')] -->
                <xsl:sort select="substring(@name, string-length(@name)-1, string-length(@name))" data-type="text" />
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>


Share : facebook icon twitter icon
XSLT Remove all attribute for one root element from xml using XSLT

XSLT Remove all attribute for one root element from xml using XSLT


By : Vinod Rayidi
Date : March 29 2020, 07:55 AM
Hope this helps I have the following root element of a big XML file: , Use
code :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                          xmlns:e2b='http://www.e2b.no/XMLSchema'
 exclude-result-prefixes="e2b">



<!-- copy everything as-is apart from exceptions below -->
<xsl:template match="node() | @*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="e2b:*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="@* | node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="/e2b:Interchange">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>
XSLT 1.0 : Remove element based on attribute of the element matching an attribute of the parent

XSLT 1.0 : Remove element based on attribute of the element matching an attribute of the parent


By : siddhesh
Date : March 29 2020, 07:55 AM
should help you out You should be using a relative path in your expression to get the ancestor date
Try this XSLT
code :
<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:template match="DONNEES[@Journee != ../../@Date]" />

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
XSLT: How to select attribute of element, based on that element has not other attribute?

XSLT: How to select attribute of element, based on that element has not other attribute?


By : Jeffrey Teruel
Date : March 29 2020, 07:55 AM
I hope this helps you . I want to select attribute of element but I know that he hasn´t other different attribute. For clarification, if element hasn´t attribute "receive Event" I want to select attribute xmi:id. , The not() function can do that. Wrapped for legibility:
code :
<xsl:template match="packagedElement[
    @xmi:type='uml:Class' 
    and (
        @name='ActivityFinal'
        or @name='Activity Final'
    )
]">
    <node
        xmi:type="uml:ActivityFinalNode"
        xmi:id="EAID_ACTIVITY{substring(@xmi:id, 14, 28)}"
        name="{@name}"
        visibility="{@visibility}"
    >
        <incoming xmi:idref="{.//message[not(@receiveEvent)]/@xmi:id}" />
    </node>
</xsl:template>
XSLT, XPath: How to get attribute of parent element with reference on attribute of his child?

XSLT, XPath: How to get attribute of parent element with reference on attribute of his child?


By : Thabo Senkhe
Date : March 29 2020, 07:55 AM
hope this fix your issue You were just missing to go up one level from ownedBehavior to subgroup to get the right xmi:id. So change your connector code to
code :
<connector xmi:idref="EAID_CONNECTOR{position()}">
     <source xmi:idref="{key('grp',key('subact', @source)/../@xmi:id)/@xmi:id}"/> 
     <target xmi:idref="{key('grp', @target)/@xmi:id}"/>
</connector>
<connector xmlns:xmi="urn:abc" xmi:idref="EAID_CONNECTOR6">
    <source xmi:idref="EAID_LIFELINE_1"/>
    <target xmi:idref="EAID_LIFELINE_2"/>
</connector>
How do I get the last child element attribute that doesn't match a parent element attribute (xslt)?

How do I get the last child element attribute that doesn't match a parent element attribute (xslt)?


By : James McGaa
Date : October 05 2020, 08:00 AM
wish helps you I am trying to get the last child element for a parent that does not have an attribute that matches one of the parent element's attributes? I have been working on this for a while and so far have come up empty handed. , I think you simply want
code :
  <xsl:template match="MainRecord">
      <MainRecord RecordNumber="{@RecordNumber}" MaxData="{AuditRecord[not(@Data = current()/@*[starts-with(local-name(), 'Data')])][last()]/@Data}"/>
  </xsl:template>
Related Posts Related Posts :
  • Support multi-language
  • Why does Hibernate @OneToOne execute multiple select queries instead of one?
  • How to modify the height and width of a LinearLayout programmatically for a customAlertDialog?
  • Java getting every second element from array list and using it as value for hash map
  • Jmap error "More than one non-option argument"
  • Thread.uncaughtExceptionHandler does not catch DataFormatException, FileAlreadyExistsException and NoSuchFileException
  • After navigating to each link in the webpage,how to get list of all forms with method =post using selenium java
  • Launch a specific Spring Boot service from a codebase containing several
  • How do I cast a Java Object into a List of integers?
  • The method andProperty(String) from the type QueryBuilder is deprecated - Javers
  • I don't understand the difference in output between System.out.println((char)b) and System.out.write((char)b)
  • How to support multiple source level targets in an annotation processor
  • Is there a way to save the obtained output from a a process object's getOutPutStream() method into a file
  • How to use item touch helper with heterogeneous view types?
  • Tap button again to confirm action
  • Getting wrong characters from Clob field in Oracle using java jdbc
  • Run multiple call in parallel go generate object using Futures
  • Unparseable date Exception java date pattern
  • Stored procedures call (namedparameterjdbctemplate)
  • com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to long
  • Java - Scanner .next() doesn't read string that contains a space
  • Set a timer for the visibility of a button
  • Unirest gives NoSuchMethodError when using asString method
  • Abstract Controller in Spring
  • Map an instance containing a list to a flatMap (using stream)
  • JPanel is added onto other Jpanel on togglebutton Click
  • Mysterious " The color components or name must be specified " error in JavaFX ListView
  • How to set up blocking asynchronous request/response in project reactor?
  • How can i achieve the same functionality with Java 8 using streams
  • How to verify a password without sending it unencrypted to a server
  • While fetching all links,Ignore logout link from the loop and continue navigation in selenium java
  • Issues using spring boot with MySQL database
  • Method unmodifiablelist() cannot be applied to given type
  • Does using the fragments lower down the load on main activity
  • Cannot read resource as stream when running jar
  • JPA criteria produce a query with just a one question point
  • Upload data to the Azure ADLS Gen2 from on-premise using Python or Java
  • Netty server send a byte[] encoded by Protobuf, but C# client Socket.Receive keeps being 0
  • How to add string at the bottom of a ScrollView
  • Using the instantiated collection type for Jackson deserialization instead of initializing a new one?
  • Firebase Realtime Database Update Data - Android Java
  • Move to main thread after another thread go to sleep
  • use of lambda and streams on nested object
  • OneDrive authentication using ADAL4J
  • How to get lines starting with some word from file and if no match get lines starting with another word
  • Is there alternative for Java's ' byte[] decodeFile = Base64.getMimeDecoder().decode(fileBase64); ' in Python?
  • filter minimum value from custom java array list
  • PowerMock static method mocking isn't taken into account for each @InjectMocks invocation
  • Spring Boot LazyInitializationException inside Transaction
  • Getting field name as string for already defined class. Is that possible?
  • List the largest possible cuboids inside a 16x16x16 matrix
  • Reading Int value of bytes from inputStream
  • How to fix text change listener error when I implement it?
  • How to send XML file to ActiveMQ?
  • @PropertyId annotation "is disallowed for this location"
  • Single Ignite node does not stop TCP discovery
  • While loop stop condition missing
  • How to register a listener on a OID / Managed Object using SNMP4J to act on set or get requests the agent receives?
  • maven issue with profiles
  • How to properly implement a sensor with SensorManager in a thread?
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org