2

I have a XML like this:

<?xml version="1.0" encoding="utf-8"?>
<batch xmlns="http://www.concursolutions.com/api/user/2011/02" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <UserProfile>
    <EmpId>123456</EmpId>
    <NewEmployeeID>
    </NewEmployeeID>
  </UserProfile>
</batch>

and I need to transform this XML to this shape:

<?xml version="1.0" encoding="utf-8"?>
<batch xmlns="http://www.concursolutions.com/api/user/2011/02" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <UserProfile>
    <EmpId>123456</EmpId>
  </UserProfile>
</batch>

This is the XSLT I tried but it didn't work:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl"
>

  <xsl:output method="xml"
              indent="yes"/>

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

  <xsl:template match="NewEmployeeID"/>

</xsl:stylesheet>

Can you please help?

Many thanks

1 Answer 1

2

NewEmployeeID is in the default namespace which uri is "http://www.concursolutions.com/api/user/2011/02". You need to use prefix that mapped to the default namespace uri to match that element :

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet .......
       xmlns:d="http://www.concursolutions.com/api/user/2011/02">
  <xsl:strip-space elements="*"/>
  .........
  <xsl:template match="d:NewEmployeeID"/>
</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

6 Comments

when I typed "<xsl:template match="d:NewEmployeeID"/>" , I got an error "Prefix 'd' is not defined".It didn't work
Notice how the prefix "d" is defined at xsl:stylesheet element in the snippet above
ok, my bad. I added "d" defined at xsl:stylesheet element. <NewEmployeeID> element totally gone but left a space like <?xml version="1.0" encoding="utf-8"?> <batch xmlns="concursolutions.com/api/user/2011/02" xmlns:i="w3.org/2001/XMLSchema-instance"> <UserProfile> <EmpId>123456</EmpId> ......SPACE HERE ...... </UserProfile> </batch> Is there anyway to get rid of this 1 line empty space in the XML?
@ms_jordan use <xsl:strip-space elements="*"/> as in the updated snippet
@ms_jordan No problem, accepting answer (when appropriate, off course) will help you to get upvoting privilege
|

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.