1

I have an xml like below:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<entry key="user">1234</entry>
<entry key="name">sam</entry>
</properties>

I want to transform the key value(key="user" to key="cm:user") into a new xml file using xslt, the output xml should be like this

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<entry key="cm:user">1234</entry>
<entry key="name">sam</entry>
</properties>

I am using the below xslt and saxon jar:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://schema.infor.com/InforOAGIS/2">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />   
<xsl:template match="@*|node()">
<xsl:result-document href="foo.xml" method="xml">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:result-document>
</xsl:template>

<xsl:template match="@key[.='user']">
<xsl:attribute name="key">
        <xsl:value-of select="'cm:user'"/>
    </xsl:attribute>
 </xsl:template>
</xsl:stylesheet>

When I run it I am getting the below error:
XTDE1490: Cannot write more than one result document to the same URI:
Could someone please help me with this..

1 Answer 1

3

You simply need

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="@key[.='user']">
<xsl:attribute name="key">
        <xsl:value-of select="'cm:user'"/>
    </xsl:attribute>
 </xsl:template>

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

If you want to define the result file name using xsl:result-document then add a template

<xsl:template match="/">
  <xsl:result-document href="foo.xml">
    <xsl:apply-templates/>
  </xsl:result-document>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.