XSLT - Prefixing elements

Hello Experts,
I need to write XSLT for this XML to XML conversion...

The structure remains the same...only all the elements needs prefixing... Any idea?

------------------------------------
Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2013 rel. 2 sp2 (x64) (http://www.altova.com)-->
<DynamicValidationValueChanges
                                dynamicValidationId="PO-RULE-PRETZELUK"
                               xsi:schemaLocation="integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd"
                               xmlns="integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd"
                               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Added id="PO789PRETZELUK">
            <Value fieldId="PONUMBER">789-777-PRETZELUK</Value>
            <SenderId property="true" scheme="AccountingSystemId">777</SenderId>
      </Added>
      <Added id="PO789PRETZELUK">
            <Value fieldId="PONUMBER">999-777-PRETZELUK</Value>
            <SenderId property="true" scheme="AccountingSystemId">777</SenderId>
      </Added>
      <Removed id="PO123PRETZELUK"></Removed>
      <Removed id="PO123PRETZELUK"></Removed>
</DynamicValidationValueChanges>


------------------------------------------------------
Output XML:  (After conversion)

<?xml version="1.0" encoding="UTF-8"?>
<ts:DynamicValidationValueChanges
        dynamicValidationId="PO-RULE-PRETZELUK"
        xmlns:ts="http://tradeshift.com/api/public/1.0">
   <ts:Added id="PO789PRETZELUK">
            <ts:Value fieldId="PONUMBER">789-777-PRETZELUK</ts:Value>
         <ts:SenderId property="true" scheme="AccountingSystemId">777</ts:SenderId>
  </ts:Added>
   <ts:Added id="PO999PRETZELUK">
            <ts:Value fieldId="PONUMBER">999-777-PRETZELUK</ts:Value>
         <ts:SenderId property="true" scheme="AccountingSystemId">777</ts:SenderId>
  </ts:Added>    
  <ts:Removed id="PO123PRETZELUK">
  </ts:Removed>
  <ts:Removed id="PO555PRETZELUK">
  </ts:Removed>
</ts:DynamicValidationValueChanges>

-------------------------

I can use XPATH and map the nodes ...any other simple way to code in XSLT?

Thanks
LVL 8
mani_saiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ken ButtersCommented:
try attached xsl file.   When I ran it, it produced the desired output shown above.
addNamespace.xsl
0
mani_saiAuthor Commented:
Thanks.

I am seeing this output:  (Attribute value are showing as element values...)  any idea?

<ts:DynamicValidationValueChanges xmlns:ts="http://tradeshift.com/api/public/1.0" xmlns="integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">PO-RULE-PRETZELUKintegration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd
      <ts:Added>PO789PRETZELUK
            <ts:Value>PONUMBER789-777-PRETZELUK</ts:Value>
            <ts:SenderId>trueAccountingSystemId777</ts:SenderId>
      </ts:Added>
      <ts:Added>PO789PRETZELUK
            <ts:Value>PONUMBER999-777-PRETZELUK</ts:Value>
            <ts:SenderId>trueAccountingSystemId777</ts:SenderId>
      </ts:Added>
      <ts:Removed>PO123PRETZELUK</ts:Removed>
      <ts:Removed>PO123PRETZELUK</ts:Removed>
</ts:DynamicValidationValueChanges>
0
Ken ButtersCommented:
try this.  This did not add it to the attributes...

Only thing I noticed it did odd was to change

from :
<Removed id="PO123PRETZELUK"></Removed>

to :
<Removed id="PO123PRETZELUK"/>

which is technically the same...
addNamespace.xsl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mani_saiAuthor Commented:
I got one step closer..now my attributes are showing with this XSLT below:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:ts="http://tradeshift.com/api/public/1.0"
                                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              version="1.0">
 
 
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="*">
    <xsl:element namespace="http://tradeshift.com/api/public/1.0" name="ts:{name()}">
      <xsl:copy-of select="namespace::* | @*"/>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
 
</xsl:stylesheet>


But still i have attribute values showing up with the elements like shown below:

<?xml version="1.0" encoding="utf-8"?>
<ts:DynamicValidationValueChanges dynamicValidationId="PO-RULE-PRETZELUK" xsi:schemaLocation="integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd" xmlns:ts="http://tradeshift.com/api/public/1.0" xmlns="integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">PO-RULE-PRETZELUKintegration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd
      <ts:Added id="PO789PRETZELUK">PO789PRETZELUK
            <ts:Value fieldId="PONUMBER">PONUMBER789-777-PRETZELUK</ts:Value>
            <ts:SenderId property="true" scheme="AccountingSystemId">trueAccountingSystemId777</ts:SenderId>
      </ts:Added>
      <ts:Added id="PO789PRETZELUK">PO789PRETZELUK
            <ts:Value fieldId="PONUMBER">PONUMBER999-777-PRETZELUK</ts:Value>
            <ts:SenderId property="true" scheme="AccountingSystemId">trueAccountingSystemId777</ts:SenderId>
      </ts:Added>
      <ts:Removed id="PO123PRETZELUK">PO123PRETZELUK</ts:Removed>
      <ts:Removed id="PO123PRETZELUK">PO123PRETZELUK</ts:Removed>
</ts:DynamicValidationValueChanges>

Any Idea?
0
mani_saiAuthor Commented:
Thanks

I dont want to see the below in my output:

1. xsi:schemaLocation="integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd integration.cbre.com.schemas.gcs.intrepid.tsdynamicvalidation.v1.xsd"

2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
0
mani_saiAuthor Commented:
Got it fixed.

Added   <xsl:template match="@xsi:schemaLocation"/>

Here is my working XSLT:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:ts="http://tradeshift.com/api/public/1.0"
                                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                version="1.0" > 
 
  <xsl:output indent="yes" omit-xml-declaration="yes"/>
 
  <xsl:template match="//*">
   
    <xsl:element namespace="http://tradeshift.com/api/public/1.0/" name="ts:{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
  </xsl:template>
 
 <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@xsi:schemaLocation"/>

</xsl:stylesheet>
0
mani_saiAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.