ich die folgende Klasse haben:XSLT-Transformation Dictionary <string, string>
public class HelloWorldDictionary
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Dictionary<string, string> Items { get; set; }
}
Und ein XSLT wie so:
<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>
Wie Sie erwarten können, die oben for- jeder funktioniert nicht ...
Das resultierende XML ist wie folgt:
<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>
Was ist die korrekte Syntax XSLT für mich jedes Schlüssel Wertepaar aus dem Artikel Wörterbuch zu greifen?
Und wie genau wenden Sie das xslt auf Ihre Klasse an? – Evk
Wie sieht Ihr aktuelles XML aus? Ich gehe davon aus, dass Sie die Klasse serialisieren, bevor Sie das Stylesheet anwenden. Fügen Sie der Frage das XML hinzu. –
Sorry Leute, ich habe es gerade hinzugefügt. – Matei