learn2earn has asked for the wisdom of the Perl Monks concerning the following question:

I have an existing site which uses transforms and xml quite heavily, I have run into a problem with modifying this one section to contain descriptions, prior to this request it only contained links. I know this should be possible to add using transforms but I am not very good at them, would it be possible to output the desriptions using $response-write? my goal is to have the descriptions display directly underneath the links, the site is using active state perl and there are several transforms depending on which xml file it is processing. I realize this is a long post but I am trying to give enough information so that the problem is understood. Not being that good at regexes I am kind of puzzled how to accomplish my goal so that I get the description(s) my sub for tutorials first the tutorials sub..
sub mTutorials { if ( $Request->ServerVariables("SERVER_NAME")->item() =~ /tempohelp/ +i ) { $str.=mLeftIndex(); my $xml = xmlFileData("Content", "tempotutorials.xml", "mTutorials() +"); if ($Request->item("DocID")->item()) { my $id = $Request->item("DocID")->item(); $xml =~ /(<tut id=\"$id\".*?\/>)/s; $str .= $1; } else { $xml =~ /(<tempo.*?<\/tempo>)/s; $str .= shadowBox("Tempo Tutorials", "<tutorials>".$1."</tutoria +ls>", ($g_docWidth/5*4-(2*$g_docSpace))); $xml =~ /(<general.*?<\/general>)/s; $str .= shadowBox("General PC Tutorials", "<tutorials>".$1."</tu +torials>", ($g_docWidth/5*4-(2*$g_docSpace))); } #$str.=mLeftIndex(); return $str; } else { $str.=mLeftIndex(); my $xml=xmlFileData("Content", "tutorials.xml", "mTutorials()"); if ($Request->item("DocID")->item()) { #my $id = $Request->item("DocID")->item(); $xml =~ /(<tut id=\"$id\".*?\/>)/s; $str .= $1; } else { $xml =~ /(<mlxchange.*?<\/mlxchange>)/s; $xml .=~/(<description.*?<\/description>)/s; $str .= shadowBox("MLXchange Tutorials &amp; Demos", "<tutorials +>".$1."</tutorials>", ($g_docWidth/5*4-(2*$g_docSpace))); $xml =~ /(<general.*?<\/general>)/s; $str .= shadowBox("General PC Tutorials", "<tutorials>".$1."</tu +torials>", ($g_docWidth/5*4-(2*$g_docSpace))); } return $str; } }
and finally an example xml file.
tutorials> <mlxchange> <tut id="15" treatment="external" src="http://www.mlxhelp.com/ +content/tutorials/mlx40/ActiveX_demo_mlx.htm" width="850" height="650 +" title="How to Install ActiveX Controls" /><description>This is a gr +eat tutorial watch it></description> </mlxchange> </tutorials>
as for transforms there are a total of 11 xsl files so I am not sure if posting them would be all that helpful, since it should be do-able using code, the site is using a here-doc. say I add the description tags above to my xml file, I am not sure how to get the contents of the description tag and the contents of the mlxchange tags to both display, there is a function called shadowbox which takes as its argument the title, the <tag>$whatever</tag> and docheight/docspace as arguments, what I really want is to stuff some other data in that box as $2 but I am not sure how to assign it properly, as I stated prior I am terrible at understanding regex. I guess I could assign a variable to the description regex as a placeholder then maybe concatenate the 2 values so that I get what I am after? <link> followed by description.. its hard to explain how this is setup, its a mess but unfortunately I am stuck with it. <code> $xml =~/(<description.*?<\/description>)/s;

Replies are listed 'Best First'.
Re: how to add descriptions?
by marto (Cardinal) on Mar 04, 2010 at 11:01 UTC

    If you are going to update a post please mark it as such, otherwise existing replies may look out of context. For example:

    Update: The update goes here

    <p><b>Update:</b> <i>The update goes here</i></p>

    Also you are missing a closing code tag.

Re: how to add descriptions?
by Anonymous Monk on Mar 03, 2010 at 16:51 UTC
    Code without context and which doesn't run is cancer
      Thanks for the cancer definition, that really helps me out:) not only will it not run but apparently its terminal. well I can get the values into a variable, but I am not sure how to get it to write the values back out into the page, thanks to the xml/xslt stuff going on. my $response-write(s) just don't go where I want the content in the page, woe is me..
        Thanks for the cancer definition, that really helps me out:)

        Great, I'm glad it solved your problem.

Re: how to add descriptions?
by Jenda (Abbot) on Mar 04, 2010 at 19:32 UTC

    You do not want to mangle XML by regexps! Believe me!

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.