XSLT transform with xml name spaces I think i'm missing something
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"开发者_StackOverflow中文版?>
<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:
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>
精彩评论