Create a new group type (like div, blockquote etc)

This forum is for all Flare issues related to styles, stylesheets and XML.
Post Reply
owilkes
Propeller Head
Posts: 68
Joined: Wed Apr 20, 2011 10:01 am
Location: London

Create a new group type (like div, blockquote etc)

Post by owilkes »

Hi All,

Any idea how to create a new group type - (like div, blockquote, fieldset, form) - note, not a new class of an existing group, but a new group alltogether.

Reason being - I need to do some bulk search'n'replace to convert the htm to an xml that a different system understands - and while I could differentiate between different classes when opening (<div> is different from <div class="xxx">) I can't differentiate when closing (it closes with </div> regardless)

<div>
<p>adsf</p>
<div class="MadCap2">
<p>fdas</p>
<p>asdf</p>
<p>asedf</p>
</div>
<p>asdf</p>
<p>asdf</p>
</div>

So - any idea what I need to add to the stylesheet to have diva, divb, divc etc as different classes?

Thanks.
wclass
Propellus Maximus
Posts: 1238
Joined: Mon Feb 27, 2006 5:56 am
Location: Melbourne, Australia

Re: Create a new group type (like div, blockquote etc)

Post by wclass »

The "group types" you mention are all HTML elements, and so, no, you can't create your own.
If all you need to do is bulk find and replace you can use a tool like FAR that uses regular expressions to find end tags that match particular div or paragraph classes.
Other editor tools like NotePad++ may also be able to do complex find/replace functions.
I happen to use FAR (not free), but you can look at it here: http://www.helpware.net/FAR/help/hh_start.htm
Margaret Hassall - Melbourne
Psider
Propellus Maximus
Posts: 819
Joined: Wed Jul 06, 2011 1:32 am

Re: Create a new group type (like div, blockquote etc)

Post by Psider »

For find and replace tools, TextCrawler is particularly good because you can preview your scripts on code samples before you run them.

You should probably also figure out what your innermost div class is and work outwards so you don't accidentally match the wrong end div (not sure of Far's capabilities in this respect). So for example, if you have classes M1, M2 and M3, make sure that M3 never surrounds an M2. (hope that makes sense.)
jjw
Sr. Propeller Head
Posts: 133
Joined: Thu May 08, 2014 4:18 pm
Location: Melbourne

Re: Create a new group type (like div, blockquote etc)

Post by jjw »

You could use an obscure but valid block level html element like, for example, "aside" if you aren't already using it for anything else.

J
AndrewCampbell
Propeller Head
Posts: 24
Joined: Thu Nov 10, 2016 4:19 am

Re: Create a new group type (like div, blockquote etc)

Post by AndrewCampbell »

owilkes wrote:Reason being - I need to do some bulk search'n'replace to convert the htm to an xml that a different system understands - and while I could differentiate between different classes when opening (<div> is different from <div class="xxx">) I can't differentiate when closing (it closes with </div> regardless)
This sounds like a job for XSLT rather than search and replace.

XSLT like this would do what I think you want.

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:template match="div[@class='xxx']">
      <xsl:element name="newElement">
         <xsl:apply-templates select="@* | node()"/>
      </xsl:element>
   </xsl:template>

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

</xsl:stylesheet>
Post Reply