[sword-devel] XSLT for OpenOffice export to OSIS Genbook
Greg Hellings
greg.hellings at gmail.com
Wed Feb 6 11:04:14 MST 2008
Daniel,
This is a very cumbersomely written XSL - I don't know why it doesn't
use the <xsl:element> tags and such for the creation of new elements
in the output. However, your problem is specified below.
On Feb 6, 2008 10:46 AM, Daniel Owens <dhowens at pmbx.net> wrote:
>
> I have several genbook projects which I want to be able to export from
> OpenOffice Writer to OSIS. I downloaded the TEI package from
> http://www.tei-c.org/wiki/index.php/TEI_OpenOffice_Package and started
> playing around (I know next to nothing about XSLT except what I could glean
> from www.w3schools.com).
>
> With some modifications I was able to get a rather rough OSIS document, at
> least with valid <div> and <p> elements nested properly. I created a
> template for Writer that has custom text styles that correspond to OSIS div
> types: bookGroup, book, chapter, section, subSection. I added x-unit
> (between book and chapter) to correspond to a unit of chapters. I arranged
> these in the template in the outline numbering according to the following
> order:
>
> 1 bookGroup
> 2 x-unit
> 3 book
> 4 chapter
> 5 section
> 6 subSection
>
> The XSLT arranges the parent-child relationships between <div> elements
> based on the outline numbering order in Writer. The type attribute is easy
> enough to add, but I am having trouble getting an osisID (The text that is
> placed in the style "book," for example, which creates the division). With
> the xslt as it is now, the chapter div looks like this:
>
> <div type="chapter" osisID="***">
> <title>Chapter 1</title>
> </div>
>
> I would like it to look like this:
>
> <div type="chapter" osisID="Chapter 1">
> <title>Chapter 1</title>
> </div>
>
> How do I retrieve that text to place it in osisID?
>
> This is the relevant template (line 371 in the xsl file):
> <xsl:template name="make-section">
> <xsl:param name="current"/>
> <xsl:param name="prev"/>
> <xsl:text disable-output-escaping="yes"><div</xsl:text>
> <xsl:text> type="</xsl:text>
> <xsl:value-of select="@text:style-name" />
> <xsl:text>"</xsl:text>
> <xsl:text> osisID="</xsl:text>
> <xsl:value-of select="***" />
This line above here is the culprit - as you see, it is told to output
the value-of the string literal ***. You need to replace this with
the XPath expression to the location that "Chapter 1" (for example) is
being pulled from. A few lines down that is being pulled in by a call
to <xsl:apply-templates> but here you can just substitute the XPath to
where the text is provided in the original XML document.
--Greg
> <xsl:text>"</xsl:text>
> <xsl:call-template name="id.attribute.literal"/>
> <xsl:text disable-output-escaping="yes">></xsl:text>
> <xsl:choose>
> <xsl:when test="$current > $prev+1">
> <title/>
> <xsl:call-template name="make-section">
> <xsl:with-param name="current" select="$current"/>
> <xsl:with-param name="prev" select="$prev+1"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <title>
> <xsl:apply-templates/>
> </title>
> <xsl:variable name="this">
> <xsl:value-of select="generate-id()"/>
> </xsl:variable>
> <xsl:for-each select="key('headchildren', $this)">
> <xsl:if test="not(parent::text:h)">
> <xsl:apply-templates select="."/>
> </xsl:if>
> </xsl:for-each>
> <xsl:choose>
> <xsl:when test="$current=1">
> <xsl:apply-templates select="key('children1',
> generate-id())"/>
> </xsl:when>
> <xsl:when test="$current=2">
> <xsl:apply-templates select="key('children2',
> generate-id())"/>
> </xsl:when>
> <xsl:when test="$current=3">
> <xsl:apply-templates select="key('children3',
> generate-id())"/>
> </xsl:when>
> <xsl:when test="$current=4">
> <xsl:apply-templates select="key('children4',
> generate-id())"/>
> </xsl:when>
> <xsl:when test="$current=5">
> <xsl:apply-templates select="key('children5',
> generate-id())"/>
> </xsl:when>
> <xsl:when test="$current=6">
> <xsl:apply-templates select="key('children6',
> generate-id())"/>
> </xsl:when>
> </xsl:choose>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> I attached the xsl file, OpenOffice Writer template, and the exported xml.
> Sorry for such a basic question, but I'm so new to xslt that I don't even
> know where to look for an answer.
>
> Daniel
> --
> PMBX license 1502
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
>
More information about the sword-devel
mailing list