Re: which one is the right module to get "this" handled properly?

Michael Ludwig <[email protected]> Mon, 16 May 2011 20:40:28 +0200
Newsgroups gmane.comp.lang.perl.xml
Message-ID <20110516184028.GA5508@Dago>
Jochen Hayek schrieb am 16.05.2011 um 19:00 (+0200):
> 
>   <text top="540" left="57" width="3" height="8" font="3">this is text
>   with <b>bold</b> pieces, pieces in <i>italics</i>, and pieces in
>   <b><i>bold and italics</i></b>, all mixed up</text>
> 
> I would like to pass the text ("this is text ..., all mixed up")
> through, as it is, together with its bold and italics mark-up, but I
> would like to deal with the elements' attribute.

Define "deal with the elements' attribute/s". Get rid of them?

> Which one would be right XML way to do that?

Definitely XSLT.

> Which one would be the right Perl module to use?

Definitely XML::LibXSLT.

But you can probably just use the command line processor xsltproc,
which is most likely available for your Linux distribution. There
are binaries for Windows, too.

Here's how to filter out the attributes from your doc:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:output indent="yes"/>

  <xsl:template match="@*|node()"><!-- identity template -->
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- attribute suppression template -->
  <xsl:template match="@*" priority="2"/>

  <!-- conserve some attributes -->
  <xsl:template match="@width | @height" priority="3"/>

</xsl:stylesheet>

Call it like this:

xsltproc get-rid-of-most-attributes.xsl your-doc.xml

-- 
Michael Ludwig
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs