How i select on xml node when xml have namespace.
Here simple xml without namespace.
="1.0"="utf-8"
<HouseList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Test</Name>
<Id>42</Id>
<HList>
<House>
<Name>Home</Name>
<Id>88</Id>
<RoomList>
<Room>
<Name>Kitchen</Name>
<Id>21</Id>
</Room>
</RoomList>
</House>
</HList>
</HouseList>
my xsl is:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Root>
<List>
<HouseListName>
<Name>
<xsl:value-of select="HouseList/Name"/>
</Name>
<Rooms>
<xsl:for-each select="HouseList/HList">
<Ho>
<Name>
<xsl:value-of select="House/Name"/>
</Name>
<R>
<xsl:for-each select="House/RoomList">
<Room>
<Name>
<xsl:value-of select="Room/Name"/>
</Name>
</Room>
</xsl:for-each>
</R>
</Ho>
</xsl:for-each>
</Rooms>
</HouseListName>
</List>
</Root>
</xsl:template>
</xsl:stylesheet>
Tranformation with C#
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("xslTest.xsl");
xslt.Transform("Ser.xml", "Result.txt");
my result is:
="1.0"="utf-8"<Root><List><HouseListName><Name>Test</Name><Rooms><Ho><Name>Home</Name><R><Room><Name>Kitchen</Name></Room></R></Ho></Rooms></HouseListName></List></Root>
all good and works.
Now i serialize datacontract my class cause i have now a dictionary in one of a class.
My xml is now:
="1.0"="utf-8"<HouseList xmlns="http://schemas.datacontract.org/2004/07/Xsl_Transformer.Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HList><House><Id>88</Id><Name>Home</Name><Note xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><a:KeyValueOfstringstring><a:Key>Sinn</a:Key><a:Value>42</a:Value></a:KeyValueOfstringstring><a:KeyValueOfstringstring><a:Key>Egal</a:Key><a:Value>88</a:Value></a:KeyValueOfstringstring></Note><RoomList><Room><Id>21</Id><Name>Kitchen</Name></Room></RoomList></House></HList><Id>42</Id><Name>Test</Name></HouseList>
How i must modify my xsl for correct transformation?
How i get access to value if key "Sinn"?
What I have tried:
direct using of xsl - only node of xml:
="1.0"="utf-8"<Root><List><HouseListName><Name></Name><Rooms /></HouseListName></List></Root>
I have try following site:
XSLT Transform XML with Namespaces - Stack Overflow[
^]
i try this
="1.0"="UTF-8"
<xsl:stylesheet version="1.0"
xmlns:d="http://schemas.datacontract.org/2004/07/Xsl_Transformer.Data"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/d">
<Root>
<List>
<HouseListName>
<Name>
<xsl:value-of select="d:HouseList/Name"/>
</Name>
<Rooms>
<xsl:for-each select="d:HouseList/HList">
<Ho>
<Name>
<xsl:value-of select="d:House/Name"/>
</Name>
<R>
<xsl:for-each select="d:House/RoomList">
<Room>
<Name>
<xsl:value-of select="d:Room/Name"/>
</Name>
</Room>
</xsl:for-each>
</R>
</Ho>
</xsl:for-each>
</Rooms>
</HouseListName>
</List>
</Root>
</xsl:template>
</xsl:stylesheet>
i get this
="1.0"="utf-8"88HomeSinn42Egal8821Kitchen42Test
and without d on match - i mean match="/" with d namespace
i get this
="1.0"="utf-8"<Root xmlns:d="http://schemas.datacontract.org/2004/07/Xsl_Transformer.Data"><List><HouseListName><Name></Name><Rooms /></HouseListName></List></Root>
i read this, but this even not work
xslt - How to 'select' from XML with namespaces? - Stack Overflow[
^]
What i can do? Have someone link or help for me?