开发者

how to interpret HTML in XSL

开发者 https://www.devze.com 2023-02-26 16:35 出处:网络
I have the following xml <results> <first-name>Carl<first-name> <data><b> This is carl\'s data </b></data>

I have the following xml

<results>
    <first-name>Carl<first-name>
    <data><b> This is carl's data </b></data>
</results>

How do I include the bold tags which is present in the <data> tag to be a part of the output but rendered as an HTML

When I say <xsl:value-of select="results/data"/> The output is

<b> This is carl's data </b>

I want to achieve "This is开发者_如何学C carl's data" as the output in bold.


Well <xsl:copy-of select="results/data/node()"/> is a start but if the requirement is part of a larger problem then you are better off writing a template for data elements which uses apply-templates to push the child nodes through some template(s) for copying HTML elements through to the output.


I am sure someone will let me know if I am being naive:

<?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" exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>

  <xsl:template match="/results">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="first-name">
    <xsl:value-of select="." />
    <xsl:text>: </xsl:text>
  </xsl:template>

  <xsl:template match="data">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="b">
    <b>
      <xsl:value-of select="." />
    </b>
  </xsl:template>
</xsl:stylesheet>
0

精彩评论

暂无评论...
验证码 换一张
取 消