XML xsl XML table

I was instructed to learn xsl in order to update some of our xml documents at work, and I studied some tutorials for xsl, although I still have to find what I would ideally be looking for ...

Since im is not working, there is a small example of heres that he is looking for:

<?xml version="1.0" encoding="UTF-8"?>
<application>
    <id>627</id>
    <name>application1</name>
    <url>www.application.com</url>
</application>

I would need to convert this to:

<?xml version="1.0" encoding="UTF-8"?>
<application>
    <id>627</id>
    <application_name>application1</application_name>
    <url>www.application.com</url>
</application>

Now, from the examples and tutorials that I saw, I could do this with a hard coded xsl sheet that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml" encoding="UTF-8"/>
    <xsl:template match="/">
        <application>
        <xsl:apply-templates/>
        </application>
    </xsl:template> 
    <xsl:template match="id">
        <id>
        <xsl:value-of select="id"/>
        <xsl:apply-templates/>
        </id>
     </xsl:template>
     <xsl:template match="name">
        <application_name>
        <xsl:value-of select="name"/>
        <xsl:apply-templates/>
        </application_name>
     </xsl:template>
     <xsl:template match="url">
        <url>
        <xsl:value-of select="url"/>
        <xsl:apply-templates/>
        </url>
     </xsl:template>
</xsl:stylesheet>

But that really would not be practical, since we have about 50 different xml documents that may need to be changed, and so I really looked for the whole template that I can use, and then only redefine the corresponding element that needs to be changed.

Does this functionality exist in xsl?

+3
2

, , . , , , , , . name.


XSLT 1.0 Saxon 6.5.5

<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="name">
        <xsl:variable name="parent" select="name(parent::*[1])"/>
        <xsl:variable name="node" select="local-name()"/>
        <xsl:element name="{$parent}_{$node}">
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

:

<?xml version="1.0" encoding="UTF-8"?>
<anyapplication>
    <id>627</id>
    <name>application1</name>
    <url>www.application.com</url>
</anyapplication>

:

<?xml version="1.0" encoding="UTF-8"?>
<anyapplication>
    <id>627</id>
    <anyapplication_name>application1</anyapplication_name>
    <url>www.application.com</url>
</anyapplication>
+2

- :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
     <xsl:template match="name">
        <application_name>
        <xsl:value-of select="name"/>
        <xsl:apply-templates/>
        </application_name>
     </xsl:template>
     <xsl:template match="not(name)">
        <xsl:copy-of select="."/>
        <xsl:apply-templates/>
     </xsl:template>
</xsl:stylesheet>
0

All Articles