1
我有下面的類:XSLT變換字典<字符串,字符串>
public class HelloWorldDictionary
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Dictionary<string, string> Items { get; set; }
}
而像這樣的XSLT:
<xsl:template match="/HelloWorldDictionary">
<html xmlns="http://www.w3.org/1999/xhtml">
<br/>
<a>
Hi there <xsl:value-of select="FirstName" /> <xsl:value-of select="LastName" />!
</a>
<br/>
<br/>
<xsl:for-each select="Items/*">
<xsl:value-of select="Key?" />
<span> : </span>
<xsl:value-of select="Value?" />
<br/>
</xsl:for-each>
</html>
正如可以預期,上述的換每個都不行...
生成的XML如下:
<HelloWorldDictionary xmlns="http://schemas.datacontract.org/2004/07/CommunicationTests.XsltEmail" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<FirstName>Foo</FirstName>
<Items xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringstring>
<a:Key>Key1</a:Key>
<a:Value>12345678912</a:Value>
</a:KeyValueOfstringstring>
<a:KeyValueOfstringstring>
<a:Key>Key2</a:Key>
<a:Value>ABC1234</a:Value>
</a:KeyValueOfstringstring>
<a:KeyValueOfstringstring>
<a:Key>Key3</a:Key>
<a:Value>Test</a:Value>
</a:KeyValueOfstringstring>
</Items>
<LastName>Bar</LastName>
什麼對我來說是正確的XSLT語法抓住從項目字典中的每個鍵值對?
你到底該如何將xslt應用到你的班級? – Evk
你的實際XML是什麼樣的?我假設你在應用樣式表之前序列化類。請將XML添加到問題中。 –
對不起,我剛添加它。 – Matei