如何停止从xsl:value-of调用中剥离HTML标签?

时间:2018-11-21 21:14:19

标签: xml xslt-1.0

我实际上在这里有两个问题。这是一个带有虚拟数据的示例XML文件:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="SRRSchedule.xsl"?>
<SRRSchedule>
  <ReportTitle>Assignments - October 2018</ReportTitle>
  <Columns>
    <Heading>Date</Heading>
    <Heading>Hall Attendant</Heading>
    <Heading>Car Park</Heading>
    <Heading>Sound</Heading>
    <Heading>Platform</Heading>
    <Heading>Mic Left</Heading>
    <Heading>Mic Right</Heading>
    <Heading>Chairman</Heading>
    <Heading>Watchtower Reader</Heading>
  </Columns>
  <MonthAssignments IncludeHeadings="true" IncludeGap="true">
    <Assignment>
      <Date Day="6" DayShort="Thu" DayFull="Thursday" Month="12" MonthShort="Dec" MonthFull="December" Year="2018">Thu, October 04</Date>
      <Name Conflict="false" Highlight="true">Name 1</Name>
      <Name Conflict="false" Highlight="false">Name 2</Name>
      <Name Conflict="false" Highlight="false">Name 3</Name>
      <Name Conflict="false" Highlight="false">Name 4</Name>
      <Name Conflict="false" Highlight="false">Name 5</Name>
      <Name Conflict="false" Highlight="false">Name 6</Name>
      <Name Conflict="false" Highlight="false">Name 7</Name>
      <Name Conflict="false" Highlight="false">Name 8</Name>
    </Assignment>
    <Assignment>
      <Date Day="6" DayShort="Thu" DayFull="Thursday" Month="12" MonthShort="Dec" MonthFull="December" Year="2018">Thu, October 04</Date>
      <Name Conflict="false" Highlight="true">Name 1</Name>
      <Name Conflict="false" Highlight="false">Name 2</Name>
      <Name Conflict="false" Highlight="false">Name 3</Name>
      <Name Conflict="false" Highlight="false">Name 4</Name>
      <Name Conflict="false" Highlight="false">Name 5</Name>
      <Name Conflict="false" Highlight="false">Name 6</Name>
      <Name Conflict="false" Highlight="false">Name 7</Name>
      <Name Conflict="false" Highlight="false">Name 8</Name>
    </Assignment>
    <Assignment>
      <Date Day="6" DayShort="Thu" DayFull="Thursday" Month="12" MonthShort="Dec" MonthFull="December" Year="2018">Thu, October 04</Date>
      <Name Conflict="false" Highlight="true">Name 1</Name>
      <Name Conflict="false" Highlight="false">Name 2</Name>
      <Name Conflict="false" Highlight="false">Name 3</Name>
      <Name Conflict="false" Highlight="false">Name 4</Name>
      <Name Conflict="false" Highlight="false">Name 5</Name>
      <Name Conflict="false" Highlight="false">Name 6</Name>
      <Name Conflict="false" Highlight="false">Name 7</Name>
      <Name Conflict="false" Highlight="false">Name 8</Name>
    </Assignment>
  </MonthAssignments>
  <MonthAssignments IncludeHeadings="true" IncludeGap="true">
    <Assignment>
      <Date Day="6" DayShort="Thu" DayFull="Thursday" Month="12" MonthShort="Dec" MonthFull="December" Year="2018">Thu, October 04</Date>
      <Name Conflict="false" Highlight="true">Name 1</Name>
      <Name Conflict="false" Highlight="false">Name 2</Name>
      <Name Conflict="false" Highlight="false">Name 3</Name>
      <Name Conflict="false" Highlight="false">Name 4</Name>
      <Name Conflict="false" Highlight="false">Name 5</Name>
      <Name Conflict="false" Highlight="false">Name 6</Name>
      <Name Conflict="false" Highlight="false">Name 7</Name>
      <Name Conflict="true" Highlight="false">Name 8</Name>
    </Assignment>
  </MonthAssignments>
  <MonthAssignments IncludeHeadings="true" IncludeGap="true">
    <Assignment>
      <Date Day="6" DayShort="Thu" DayFull="Thursday" Month="12" MonthShort="Dec" MonthFull="December" Year="2018">Thu, October 04</Date>
      <SpecialEvent>Circuit Assembly—Be Bold!</SpecialEvent>
    </Assignment>
  </MonthAssignments>
  <Note>
    All assigned brothers should try to arrive at least <u><b>15 minutes</b></u> before the meeting to confirm duties, set up and test the sound and prepare the platform.
  </Note>
</SRRSchedule>

这是CSS文件:

body
{
    font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    font-size: 12pt;
}

.textReportTitle {
    text-align: center;
    font-size: 18pt;
    font-weight: 700;
}

table {
    border-collapse: collapse;
    width: 100%;
}

table td {
    height: 14pt;
    border: 1px solid black;
    padding: 1mm;
}

.cellHeading {
    font-weight: 700;
    background-color: red;
}

.cellDate {
    background-color: yellow;
}

.cellName {

}

.cellHighlight {
    background-color: cyan;
}

.cellConflict {
    background-color: gray;
}

.cellSpecialEvent {
    text-align: center; 
    font-style: italic;
}

.cellNote {
    text-align: center;
    background-color: darkgrey;
}

.cellGap {
    max-height: 5mm;
    background-color: orange;
}

这是XSL脚本:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output method="html" indent="yes" version="4.01"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    doctype-public="//W3C//DTD XHTML 1.0 Transitional//EN"/>
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <link rel="stylesheet" type="text/css" href="SRRSchedule.css"/>
        <title>Report</title>
      </head>
      <body>
        <xsl:apply-templates select="SRRSchedule/ReportTitle"/>
        <table cellpadding="0" cellspacing="0">
          <xsl:apply-templates select="SRRSchedule/MonthAssignments"/>
          <xsl:apply-templates select="SRRSchedule/Note"/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="ReportTitle">
    <p class="textReportTitle">
      <xsl:value-of select="."/>
    </p>
  </xsl:template>

  <xsl:template match="MonthAssignments">
    <xsl:if test="@IncludeHeadings">
      <tr>
        <xsl:apply-templates select="/SRRSchedule/Columns/Heading"/>
      </tr>
    </xsl:if>
    <xsl:apply-templates select="Assignment"/>
    <xsl:if test="@IncludeGap='true'">
      <xsl:call-template name="GapRow"/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Heading">
    <td class="cellHeading">
      <xsl:value-of select="."/>
    </td>
  </xsl:template>

  <xsl:template match="Assignment">
    <tr>
      <xsl:apply-templates select="Date"/>
      <xsl:apply-templates select="Name"/>
      <xsl:apply-templates select="SpecialEvent"/>
    </tr>
  </xsl:template>

  <xsl:template match="Date">
    <td class="cellDate">
      <xsl:value-of select="."/>
    </td>
  </xsl:template>

  <xsl:template match="Name">
    <td class="cellName">
      <xsl:choose>
        <xsl:when test="@Highlight='true'">
          <xsl:attribute name="class">cellHighlight</xsl:attribute>
        </xsl:when>
        <xsl:when test="@Conflict='true'">
          <xsl:attribute name="class">cellConflict</xsl:attribute>
        </xsl:when>
      </xsl:choose>
      <xsl:value-of select="."/>

      <!-- Test if the name is empty -->
      <xsl:if test=".=''">
        <xsl:text>None</xsl:text>
      </xsl:if>
    </td>
  </xsl:template>

  <xsl:template match="Note">
    <tr>
      <td class="cellNote">
        <xsl:attribute name="colspan">
          <xsl:value-of select="count(/SRRSchedule/Columns/Heading)"/>
        </xsl:attribute>
        <!-- Why does this not apply the HTML syntax? -->
        <xsl:value-of select="." disable-output-escaping="yes"/>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="SpecialEvent">
    <td class="cellSpecialEvent">
      <xsl:attribute name="colspan">
        <xsl:value-of select="count(/SRRSchedule/Columns/Heading)-1"/>
      </xsl:attribute>
      <xsl:value-of select="."/>
    </td>
  </xsl:template>

  <xsl:template name="GapRow">
    <!-- Why is this row not showing as 5mm high? -->
    <tr>
      <td class="cellGap">
        <xsl:attribute name="colspan">
          <xsl:value-of select="count(/SRRSchedule/Columns/Heading)"/>
        </xsl:attribute>
        <xsl:text> </xsl:text>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

这是转换的样子:

Results

在XML文件中,我有:

  <Note>
    All assigned brothers should try to arrive at least <u><b>15 minutes</b></u> before the meeting to confirm duties, set up and test the sound and prepare the platform.
  </Note>

注意我那里有一些HTML语法吗?因此,我期望“ 15分钟”要大胆并强调。但是,这没有发生。所有HTML标签都将被剥离。

我的另一个问题与设置“行间距”行的高度有关。但是我将把它作为一个单独的问题。

0 个答案:

没有答案