tags:

views:

46

answers:

1

I just used a docbook2dita.xsl, and it worked for the most part, but one issue I ran into were:

<section xml:id="555" xmlns="http://docbook.org/ns/docbook"&gt;

turned into:

<reference id="555.d12e1">

I'm thinking it doesn't matter that the namespace dissappeared, but the id got really screwy. What would be a good fix to this? Another XSL after the first transform?

A: 

If you want to overwrite the way one stylesheet process some node (@xml:id i.e.), import the stylesheet and declare your own rule:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:import href="docbook2dita.xsl"/>
    <xsl:template match="@xml:id">
        <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>

EDIT: If it's garanteed a one-to-one transformation (i.e. section to reference), then this stylesheet:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:import href="test2.xsl"/>
    <xsl:template match="*[@xml:id]">
        <xsl:variable name="vResult">
            <xsl:apply-imports/>
        </xsl:variable>
        <xsl:apply-templates select="msxsl:node-set($vResult)/*" mode="copy">
            <xsl:with-param name="pId" select="@xml:id"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="/*/@id" mode="copy"/>
    <xsl:template match="node()|@*" mode="copy">
        <xsl:param name="pId" select="/.."/>
        <xsl:copy>
            <xsl:apply-templates select="@*" mode="copy"/>
            <xsl:apply-templates select="$pId" mode="copy"/>
            <xsl:apply-templates select="node()" mode="copy"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

It should preserve @xml:id and strip any calculate @id.

As proof, this input:

<root>
    <section xml:id="555" xmlns="http://docbook.org/ns/docbook"/&gt;
    <section id="111" xmlns="http://docbook.org/ns/docbook"/&gt;
</root>

With this imported stylesheet test2.xsl:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:db="http://docbook.org/ns/docbook"
 exclude-result-prefixes="db">
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="db:section">
        <reference id="{(@id|@xml:id)[1]}-sufix"/>
    </xsl:template>
</xsl:stylesheet>

Output:

<root>
    <reference xml:id="555"></reference>
    <reference id="111-sufix" />
</root>

Note: If this doesn't help you, you should post a question in DITA forum

Alejandro
hmm, no luck. it did the dita transform, but the same problem persists
Ace
@Ace: Then the `@id` is calculate in other way not matching `@xml:id`. Check my edit.
Alejandro
Sorry, still no luck, thanks for thr try though!
Ace
@Ace: Then you should ask to the stylesheet develeper.
Alejandro
@Alejandro: Not sure thats possible, so i applied and transform before the docbook2dita so replace xml:id to id which solves the issue
Ace