xml - XSLT 1.0 How to convert < > to Adobe InDesign namespace -
indesign supports special formatting attributes, let me embed reference paragraph, character, table, or cell style in xml file. when xml file imported , laid out, indesign uses referenced style format element. how convert <
, >
etc. aid namespace.
this input:
<article> <para><em>eheniendel il <strong>evel</strong></em>mos illanit atatur <strong>reptatiat</strong></para> <para>os veles qui ne voluptaquam, quid qui <strong>rehendi</strong>.</para> <para>berchicide <strong>reperumet</strong> ilicitatin <em>cus</em></para> <para>dellabores ant. <em>arte</em> dandae si <strong>rectur</strong>?</para> <para>am, voloribus doluptatem aut, <em>cor</em> aut <em>conse</em></para>
i need such output:
<article> <para> <em aid:cstyle="italic">eheniendel il <em aid:cstyle="bold-italic">evel</em> </em>mos illanit atatur <em aid:cstyle="bold">reptatiat</em> </para> <para>os veles qui ne voluptaquam, quid qui <em aid:cstyle="bold">rehendi</em>.</para> <para>berchicide <em aid:cstyle="bold">reperumet</em> ilicitatin <em aid:cstyle="italic">cus</em> </para> <para>dellabores ant. <em aid:cstyle="italic">arte</em> dandae si <em aid:cstyle="bold">rectur</em>?</para> <para>am, voloribus doluptatem aut, <em aid:cstyle="italic">cor</em> aut <em aid:cstyle="italic">conse</em> </para> </article>
i need convert:
<em> <em aid:csytle = "italic"> <strong> <em aid:csytle = "bold"> <strong><em> or <em><strong> <em aid:csytle = "bold-italic">
i made xslt 1.0 stylesheet works normal xml elements <em>
end <strong>
. how improve input?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:aid="http://ns.adobe.com/adobeindesign/4.0/" xmlns:aid5="http://ns.adobe.com/adobeindesign/5.0/"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> <xsl:template match="/root"> <root xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:aid="http://ns.adobe.com/adobeindesign/4.0/" xmlns:aid5="http://ns.adobe.com/adobeindesign/5.0/"> <xsl:apply-templates select="@* | node()"/> </root> </xsl:template> <xsl:template match="strong"> <xsl:element name="em"> <xsl:attribute name="aid:cstyle"> <xsl:value-of select="'bold'"/> </xsl:attribute> <xsl:apply-templates/> </xsl:element> </xsl:template> <xsl:template match="em"> <xsl:element name="em"> <xsl:attribute name="aid:cstyle"> <xsl:value-of select="'italic'"/> </xsl:attribute> <xsl:apply-templates/> </xsl:element> </xsl:template> <xsl:template match="em[../../strong]|strong[../../em]"> <xsl:element name="em"> <xsl:attribute name="aid:cstyle"> <xsl:value-of select="'bold-italic'"/> </xsl:attribute> <xsl:apply-templates/> </xsl:element> </xsl:template>
the easiest solution perform 2 xsl transformations in series: first transformation do:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="para"> <xsl:copy> <xsl:value-of select="." disable-output-escaping="yes"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
and save result file. second transformation apply stylesheet resulting file.
the alternative painful process of parsing escaped xml using string functions in recursive named template.
Comments
Post a Comment