Skip to content

Commit

Permalink
Switch merge to use XSLT 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Jan 17, 2024
1 parent 82ee09d commit 5a4c6af
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run DITA-OT Unit Test
uses: jason-fox/dita-unit-test-action@master
with:
dita-ot-version: '4.0'
dita-ot-version: '4.1.2'
plugin: 'fox.jason.translate.xliff'
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
Expand Down
42 changes: 22 additions & 20 deletions xsl/1/xliff-merge.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,28 @@
<xsl:copy-of select="$namespaces" />
<!-- xsl:copy-of select="@*" is the standard way of copying all attributes. -->
<xsl:copy-of select="@*" />
<xsl:for-each select="collection($path)">
<!-- xsl:copy-of copies nodes and all their descendants -->
<xsl:apply-templates select="document(document-uri(.))/node()" mode="xliff" />
</xsl:for-each>
<!-- copies nodes and all their descendants -->
<xsl:merge>
<xsl:merge-source for-each-item="collection($path)/*/*" select="." >
<xsl:merge-key select="@id" order="ascending" />
</xsl:merge-source>
<xsl:merge-action>
<xsl:for-each select="current-merge-group()">
<xsl:if test="count(//trans-unit) &gt; 0">
<xsl:element name="file">
<!--xsl:attribute name="id" select="position()" /-->
<xsl:for-each select="@*">
<xsl:variable name="name" select="name()" />
<xsl:attribute name="{$name}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="file" />
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:merge-action>
</xsl:merge>
</xsl:element>
</xsl:template>

Expand All @@ -68,20 +86,4 @@
<xsl:apply-templates select="node()|@*" mode="file" />
</xsl:copy>
</xsl:template>

<xsl:template match="*" mode="xliff">
<xsl:for-each select="*">
<xsl:if test="//trans-unit">
<xsl:element name="file">
<xsl:for-each select="@*">
<xsl:variable name="name" select="name()" />
<xsl:attribute name="{$name}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="file" />
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
49 changes: 25 additions & 24 deletions xsl/2/xliff-merge.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,31 @@
<xsl:namespace name="fs" select="'urn:oasis:names:tc:xliff:fs:2.0'" />
<!-- xsl:copy-of select="@*" is the standard way of copying all attributes. -->
<xsl:copy-of select="@*" />
<xsl:for-each select="collection($path)">
<!-- provided that at least one unit exists -->
<xsl:if test="count(document(document-uri(.))/node()//unit) &gt; 0">
<!-- xsl:copy-of copies nodes and all their descendants -->
<xsl:apply-templates select="document(document-uri(.))/node()" mode="xliff">
<xsl:with-param name="idCount" select="position()" />
</xsl:apply-templates>
</xsl:if>
</xsl:for-each>


<!-- copies nodes and all their descendants -->
<xsl:merge>
<xsl:merge-source for-each-item="collection($path)/*/*" select="." >
<xsl:merge-key select="@id" order="ascending" />
</xsl:merge-source>
<xsl:merge-action>
<xsl:for-each select="current-merge-group()">
<xsl:if test="count(//unit) &gt; 0">
<xsl:element name="file">
<xsl:attribute name="id" select="position()" />
<xsl:for-each select="@*">
<xsl:variable name="name" select="name()" />
<xsl:attribute name="{$name}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="file" />
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:merge-action>
</xsl:merge>

</xsl:element>
</xsl:template>

Expand All @@ -85,19 +101,4 @@
</xsl:copy>
</xsl:template>

<xsl:template match="*" mode="xliff">
<xsl:param name="idCount" />
<xsl:for-each select="*">
<xsl:element name="file">
<xsl:attribute name="id" select="$idCount" />
<xsl:for-each select="@*">
<xsl:variable name="name" select="name()" />
<xsl:attribute name="{$name}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates mode="file" />
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 5a4c6af

Please sign in to comment.