轉換XHTML到XAML我有以下XML使用XSLT
User entered text : Normal **Bold** *Italic*
u̲n̲d̲e̲r̲l̲i̲n̲e̲
***BoldItalic*** ***B̲o̲l̲d̲I̲t̲a̲l̲i̲c̲U̲n̲d̲e̲r̲l̲i̲n̲e̲***
產生的XHTML字符串存儲在數據庫中的表。
<QuestionText xml:space="preserve">
<p>Normal
<b>Bold </b>
<i>Italic </i>
<u>Underline </u>
<b>Bold <i>BoldItalic </i>Bold </b>
<b><i>BoldItalic </i></b>
<b><i><u>BoldItalicUnderline</u></i></b>
</p>
<p/>
<p/>
<p/>
</QuestionText>
我需要轉換到.NET X(A)ML如下
<Section>
<Paragraph>
<Span Text="Nornal " />
<Span FontWeight="Bold" Text="Bold " />
<Span FontStyle="Italic" Text="Italic " />
<Span Text="Underline " UnderlineDecoration="Line" />
<Span FontWeight="Bold" Text="Bold " />
<Span FontStyle="Italic" FontWeight="Bold" Text="BoldItalic " />
<Span FontWeight="Bold" Text="Bold " />
<Span FontStyle="Italic" FontWeight="Bold" Text="BoldItalic " />
<Span FontStyle="Italic" FontWeight="Bold" Text="BoldItalicUnderline" UnderlineDecoration="Line" />
</Paragraph>
<Paragraph/>
<Paragraph/>
<Paragraph/>
</Section>
我試着用這個XSLT沒有運氣
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="QuestionText">
<Section>
<xsl:apply-templates/>
</Section>
</xsl:template>
<xsl:template match="b|i|u|p/text()" >
<span>
<xsl:attribute name="Text">
<xsl:value-of select="current()"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="name()"/>
</xsl:attribute>
<xsl:attribute name="parent">
<xsl:value-of select="name(..)"/>
</xsl:attribute>
<xsl:if test=".=i">
<xsl:attribute name="FontStyle">italic</xsl:attribute>
</xsl:if>
<xsl:if test=".=b">
<xsl:attribute name="FontWeight">bold</xsl:attribute>
</xsl:if>
<xsl:if test=".=u">
<xsl:attribute name="UnderlineDecoration">line</xsl:attribute>
</xsl:if>
</span>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p">
<Paragraph>
<xsl:apply-templates/>
</Paragraph>
</xsl:template>
</xsl:stylesheet>
XSLT的任何幫助,高度讚賞。
您在源XML中顯示的數據不是有效的XML。我已經爲您的問題應用了降價,以便從字面上顯示文字,但我完全不確定您在問什麼。 – Borodin
大家注意:'̲'是Unicode組合下劃線字符。 – Borodin
沒有運氣......在什麼意義上? – JLRishe