Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Moving a tag within text with XML::Twig

by graff (Chancellor)
on Sep 25, 2005 at 15:42 UTC ( [id://494915]=note: print w/replies, xml ) Need Help??


in reply to Moving a tag within text with XML::Twig

Your use of grep in a void context looks like a mistake. You realize that this does not change the content of @foots, don't you? I expect you want the list returned by grep to be the iterator in the following for loop:
for ( grep { $_->prev_sibling_text =~ m<([,.])\s*$> } @foots ) { ...
As for cases where the following sibling has no text (note: there are "prev_sibling()" and "next_sibling()" methods for elt objects), it may be a matter of understanding your document structure to determine whether you need to insert a new elt as a next sibling in order to move the punctuation text into that, or whether you can just assign text content (the punctuation) to the next sibling, whatever it may be.

(I suspect that inserting a new elt as the next sibling will be the way to go -- it covers both cases of "no next sibling" and "next sibling has no text". Or maybe you should review the "local typographical rules" to see if maybe the footnote does not need to be placed before punctuation when no text follows. Frankly, I think the "rule" you stated is suspect -- having footnotes after punctuation seems like a common practice.)

In any case, are you sure that looking just for final period or comma is sufficient? What about question/exclamation marks, quotation marks, parens, and any combination thereof?

Replies are listed 'Best First'.
Re^2: Moving a tag within text with XML::Twig
by skillet-thief (Friar) on Sep 25, 2005 at 18:06 UTC
    Your use of grep in a void context looks like a mistake. You realize that this does not change the content of @foots, don't you? I expect you want the list returned by grep to be the iterator in the following for loop:
    + for ( grep { $_->prev_sibling_text =~ m<([,.])\s*$> } @foots ) {

    A mistake, or another rung on the learning curve. Or both. Thanks.

    As for cases where the following sibling has no text (note: there are "prev_sibling()" and "next_sibling()" methods for elt objects), it may be a matter of understanding your document structure to determine whether you need to insert a new elt as a next sibling in order to move the punctuation text into that, or whether you can just assign text content (the punctuation) to the next sibling, whatever it may be.

    This is my problem, and this is what I don't quite understand. Suppose I had data like this:

    <a>Text text <b>Footnote code</b></a>

    How, with XML::Twig do I add text between the </b> and </a> tags? Maybe I don't understand XML terminology well enough, but I kind of thought that adding an element woud mean doing something like this:

    <a>Text text <b>Footnote code</b><a>The new text</a></a>

    In other words, how do I specify that the child I want to add to the original <a> element is just a text element?

    Or maybe you should review the "local typographical rules" to see if maybe the footnote does not need to be placed before punctuation when no text follows. Frankly, I think the "rule" you stated is suspect -- having footnotes after punctuation seems like a common practice.)

    This is all in French, and French typography rules want the footnote reference before the punctuation. This is a little-known rule, even amongst French authors, which is partly why I'm building this filter.

    In any case, are you sure that looking just for final period or comma is sufficient? What about question/ exclamation marks, quotation marks, parens, and any combination thereof?

    Exactly. This is phase one of figuring out how to do this. Next comes all the fun dealing with the different punctuation possibilities. Quotations marks (»), question marks, colons, semicolons, and exclamation points all must be preceeded by a non-breaking space.

    sub jf { print substr($_[0], -1); jf( substr($_[0], 0, length($_[0])-1)) if length $_[0] > 1; } jf('gro.alubaf@yehaf');

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://494915]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found