Project

Profile

Help

Bug #5480 » Sample_Transform_XSLT.xsl

Example Transform XSLT - John Crane, 2022-05-10 15:59

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" exclude-result-prefixes="xs" version="2.0">
<xsl:output version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- IMPORTANT!!!!!! remove "_test" from the result-document href before use. -->
<xsl:template match="/">
<xsl:result-document href="{descendant::article-id[@pub-id-type='other' and @specific-use='base-file-name']}.xml">
<xsl:apply-templates>
</xsl:apply-templates>
</xsl:result-document>
</xsl:template>
<!-- remove stuff that might be added during the editing cycle -->
<xsl:template match="processing-instruction(fontoxml-text-placeholder)">
</xsl:template>
<xsl:template match="processing-instruction(fontoxml-annotation-start)">
</xsl:template>
<xsl:template match="processing-instruction(fontoxml-annotation-end)">
</xsl:template>
<xsl:template match="processing-instruction(fontoxml-annotation-reply)">
</xsl:template>
<xsl:template match="processing-instruction(AuthorQuery)">
</xsl:template>
<xsl:template match="article/@id">
</xsl:template>
<xsl:template match="styled-content[@specific-use='bookmark']">
<xsl:copy-of select="./child::node()" />
</xsl:template>
<!-- in rows with @content-type="heading" change td back to th unless it has @content-type="was-td", in which case it should remain td, got it? -->
<xsl:template match="tr[@content-type='header']">
<xsl:element name="tr">
<xsl:for-each select="./node()">
<xsl:if test="self::td[not(@content-type)]">
<xsl:element name="th">
<xsl:if test=".[@align]">
<xsl:attribute name="align">
<xsl:value-of select="./@align" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@colspan]">
<xsl:attribute name="colspan">
<xsl:value-of select="./@colspan" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@rowspan]">
<xsl:attribute name="rowspan">
<xsl:value-of select="./@rowspan" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@valign]">
<xsl:attribute name="valign">
<xsl:value-of select="./@valign" />
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="./child::node()" />
</xsl:element>
</xsl:if>
<xsl:if test="self::td[@content-type='was-td']">
<xsl:element name="td">
<xsl:if test=".[@align]">
<xsl:attribute name="align">
<xsl:value-of select="./@align" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@colspan]">
<xsl:attribute name="colspan">
<xsl:value-of select="./@colspan" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@rowspan]">
<xsl:attribute name="rowspan">
<xsl:value-of select="./@rowspan" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@valign]">
<xsl:attribute name="valign">
<xsl:value-of select="./@valign" />
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="./child::node()" />
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="th[@content-type='td']">
<xsl:element name="td">
<xsl:if test=".[@align]">
<xsl:attribute name="align">
<xsl:value-of select="./@align" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@colspan]">
<xsl:attribute name="colspan">
<xsl:value-of select="./@colspan" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@rowspan]">
<xsl:attribute name="rowspan">
<xsl:value-of select="./@rowspan" />
</xsl:attribute>
</xsl:if>
<xsl:if test=".[@valign]">
<xsl:attribute name="valign">
<xsl:value-of select="./@valign" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="graphic">
<xsl:element name="graphic">
<xsl:attribute name="xlink:href">
<xsl:value-of select="concat(./@*[namespace-uri()='http://www.w3.org/1999/xlink' and local-name()='href'],'.',./@mime-subtype)" />
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
(1-1/2)