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>&lt;em&gt;eheniendel il &lt;strong&gt;evel&lt;/strong&gt;&lt;/em&gt;mos illanit atatur &lt;strong&gt;reptatiat&lt;/strong&gt;</para>     <para>os veles qui ne voluptaquam, quid qui &lt;strong&gt;rehendi&lt;/strong&gt;.</para>     <para>berchicide &lt;strong&gt;reperumet&lt;/strong&gt; ilicitatin &lt;em&gt;cus&lt;/em&gt;</para>     <para>dellabores ant. &lt;em&gt;arte&lt;/em&gt; dandae si &lt;strong&gt;rectur&lt;/strong&gt;?</para>     <para>am, voloribus doluptatem aut, &lt;em&gt;cor&lt;/em&gt; aut &lt;em&gt;conse&lt;/em&gt;</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:

&lt;em&gt; <em aid:csytle = "italic"> &lt;strong&gt; <em aid:csytle = "bold"> &lt;strong&gt;&lt;em&gt; or &lt;em&gt;&lt;strong&gt;  <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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -