LoginSignup
0
1

More than 5 years have passed since last update.

Thymeleaf で不要な要素を削除する XSL

Posted at
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" method="xml"/>

  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*[@th:remove='all']" /><!-- th:remove=all 要素は削除 -->
  <xsl:template match="*[@th:remove='all-but-first']">
    <!-- th:remove=all-but-first 要素は最初を残して削除 -->
    <xsl:copy>
      <xsl:for-each select="@*">
        <xsl:copy/>
      </xsl:for-each>
      <xsl:apply-templates select="*[1]" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*[@th:include] | *[@th:replace] | *[@th:text]">
    <!-- 中身が要らない要素はざくっと捨てる -->
    <xsl:copy>
      <xsl:for-each select="@*">
        <xsl:copy/>
      </xsl:for-each>
      <xsl:value-of select="translate(@th:*, '@$#{}', '')" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="comment()"><!-- コメントは Thymeleaf コメントに変換 -->
    <xsl:comment>/*<xsl:value-of select="." />*/</xsl:comment>
  </xsl:template>
</xsl:stylesheet>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1