我有一个转换XML文档,定义我们的HTML为HTML格式的相当简单的XSL样式表(请不要问为什么,这只是我们必须做的方式...)什么是更好的XSL样式创建HTML标签的方法?
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="HtmlElement">
<xsl:element name="{ElementType}">
<xsl:apply-templates select="Attributes"/>
<xsl:value-of select="Text"/>
<xsl:apply-templates select="HtmlElement"/>
</xsl:element>
</xsl:template>
<xsl:template match="Attributes">
<xsl:apply-templates select="Attribute"/>
</xsl:template>
<xsl:template match="Attribute">
<xsl:attribute name="{Name}">
<xsl:value-of select="Value"/>
</xsl:attribute>
</xsl:template>
问题出来了,当我跑过HTML需要改造的这一点点:
<p>
Send instant ecards this season <br/> and all year with our ecards!
</p>
中间的<br/>
打破了转型的逻辑,并给了我唯一的段落块的前半部分:Send instant ecards this season <br></br>
。尝试进行转换的XML看起来像:
<HtmlElement>
<ElementType>p</ElementType>
<Text>Send instant ecards this season </Text>
<HtmlElement>
<ElementType>br</ElementType>
</HtmlElement>
<Text> and all year with our ecards!</Text>
</HtmlElement>
建议?
现在这将如何影响一个' ...'标签?我不确定我是否理解你要回答的问题 – CallMeTroggy
@CallMeTroggy嗯,首先,这个XSL根据你在问题中指定的XML输入生成你想要的HTML输出。所以这应该是一些东西;)只要它们遵循你在问题中提出的XML结构,它也可以很好地适用于任何嵌套的HTML元素 - 只需试一试! – phihag
啊哈!是的,这正是我所需要的。我对XSL还比较陌生,但我并没有真正看到/理解管道的作用(仍然有点不确定,但是现在有了更好的把握)。谢谢@phihag! – CallMeTroggy