0

I think I'm missing something when it comes to namespaces and xml, I'm trying to transform xml with an XSLT

Input

<?xml version="1.0" encoding="utf-8"?>
<MySomeObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<_x003C_Name_x003E_k__BackingField>Jon</_x003C_Name_x003E_k__BackingField>
    <_x003C_Id_x003E_k__BackingField i:nil="true"  />
</MySomeObject>

XSLT

<?xml version="1.0" encoding="us-ascii"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:template match="/">              
Name: <xsl:value-of select="MySomeObject/_x003C_Name_x003E_k__BackingField"/>
  </xsl:template>
</xsl:stylesheet>

Gives me the expected output Name: Jon

However

Input:

<?xml version="1.0" encoding="utf-8"?>
<MySomeObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://schemas.datacontract.org/2004/07/My.Object.Name.Space">
<_x003C_Name_x003E_k__BackingField>Jon</_x003C_Name_x003E_k__BackingField>
    <_x003C_Id_x003E_k__BackingField i:nil="true"  />
</MySomeObject>

XSLT:

<?xml version="1.0" encoding="us-ascii"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://schemas.datacontract.org/2004/07/My.Object.Name.Space">
  <xsl:template match="/">              
Name: <xsl:value-of select="MySomeObject/_x003C_Name_x003E_k__BackingField"/>
  </xsl:template>
</xsl:stylesheet>

Does not give me the same output, it only returns Name:

1 Answer 1

4

Try this:

<?xml version="1.0" encoding="us-ascii"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:other="http://schemas.datacontract.org/2004/07/My.Object.Name.Space">
  <xsl:template match="/">              
    Name:
    <xsl:value-of 
         select="other:MySomeObject/other:_x003C_Name_x003E_k__BackingField"/>
  </xsl:template>
</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

1 Comment

That worked, i didn't realize you shorted the value of the schema after :other

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.