Custom filtering stylesheet for component elements

The component-filter.xsl custom-filtering stylesheet templates provided in this example will copy the values from the component elements in the topic prolog elements to the @otherprops attribute of the topicref elements.

Here is the topicref template for gathering component values into the otherprops attribute.
<xsl:template match="element()[contains(@class, ' map/topicref ')][@href != '']">
  <xsl:variable name="components">
    <xsl:apply-templates mode="get-components" select="." />
  </xsl:variable>
  <xsl:variable name="existing-otherprops" select="@otherprops" />
  <xsl:variable name="otherprops">
    <xsl:value-of select="normalize-space(concat($components,' ',$existing-otherprops))" />
  </xsl:variable>
  <xsl:copy>
    <xsl:apply-templates select="@*[name() != 'otherprops']" />
    <xsl:if test="$otherprops != ''">
      <xsl:attribute name="otherprops">
        <xsl:value-of select="$otherprops" />
      </xsl:attribute>
      <xsl:if test="$debug = 'true'">
        <xsl:message>
          <xsl:value-of select="concat('otherprops=',$otherprops)" />
        </xsl:message>
      </xsl:if>
    </xsl:if>
    <xsl:apply-templates />
  </xsl:copy>
</xsl:template>
Here is the topicref template for retrieving DITA component values.
<xsl:template match="element()[contains(@class, ' map/topicref ')][@href != '']" mode="get-components">
  <xsl:for-each select="document(@href)">
    <xsl:for-each select="//element()[contains(@class, ' topic/component ')]">
      <xsl:value-of select="normalize-space()" />
      <xsl:if test="position() != last()">
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>