views:

107

answers:

1

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"&gt;
<_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"&gt;
  <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"&gt;
<_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"&gt;
  <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:

+3  A: 

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"&gt;
  <xsl:template match="/">              
    Name:
    <xsl:value-of 
         select="other:MySomeObject/other:_x003C_Name_x003E_k__BackingField"/>
  </xsl:template>
</xsl:stylesheet>
Rubens Farias
That worked, i didn't realize you shorted the value of the schema after :other
Chris Marisic