[SlugBug] a perl/xslt question. potentially inappropriate.

Mike Dewar m.dewar at sheffield.ac.uk
Sat Apr 16 15:01:45 BST 2005


That's great! I was making things harder than they needed to be, and i 
didn't realise you could apply a template that you hadn't created... I 
suppose if you don't specify a template it just gives you the text in 
the tag?

Would making it a bit more human-readable be a huge problem? The reason 
I ask is that the wiki should be human-editable once it's up... this 
mucking about with xml should just be to populate the wiki to begin 
with. Everything after this should remain in the wiki. Having readable 
text will make it easier for people who aren't used to editing things 
like this to go ahead and edit the wiki....

What you've given me already solves the initial problem though, so 
thankyou very much. I'm going to go back and edit my stylesheet with 
this in mind...

Cheers,

Mike D

On 16 Apr 2005, at 12:56, Chris J wrote:

>
> And Lo! The Great Prophet Mike Dewar uttered these words of wisdom:
>>
>> Here's the XML (from the Scilab Source)
>>
>> <P>
>>      For a vector or a matrix <VERB>x</VERB>, <VERB>y=sum(x)</VERB>
>> returns in the scalar <VERB>y</VERB> the sum of all the entries
>>      of <VERB>x</VERB>.</P>
>>
>> and here's what i want it to look like for the wiki:
>>
>> <P>
>>      For a vector or a matrix '''x''', '''y=sum(x)'''  returns in the
>> scalar '''y''' the sum of all the entries
>>      of '''x'''.</P>
>>
>> Can anyone help? I think the problem I'm having is that the VERB 
>> things
>> are nested in the text of the P tags. I can only seem to get the all
>> the text() elements of P then the text inside the VERB tags. I cant
>> keep them nested...
>
> Does whitespace matter? If not, then running that fragment as an XML
> document in its own right through this stylesheet with Sablotron gives 
> the
> results you're looking for...
>
> <?xml version="1.0"?>
>
> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> version="1.0">
>
>         <xsl:template match="/">
>                 <xsl:apply-templates />
>         </xsl:template>
>
>         <xsl:template match="P">
>                 <P><xsl:apply-templates /></P>
>         </xsl:template>
>
>         <xsl:template match="VERB">
>                 '''<xsl:apply-templates />'''
>         </xsl:template>
>
> </xsl:transform>
>
> What this does is match the root node first (as an entry point 
> obviously),
> then recursively processes all XML nodes it comes across. When it comes
> across <P>, it runs the template for match="P", which essentially 
> copies
> the  input to the output, wrapped in <P>. Note though I'm doing this 
> with
> apply-templates again, so we get recursive processing of nodes. This 
> means
> that VERB gets picked up and processed by the appropriate template...
>
> This spits out:
> <P>
>         For a vector or a matrix
>                 '''x'''
>         ,
>                 '''y=sum(x)'''
>
>         returns in the scalar
>                 '''y'''
>          the sum of all the entries
>         of
>                 '''x'''
>         .</P>
>
> See why I asked if whitespace matters?. If this is simply going to 
> produce
> another XML document, or a HTML document, then the whitespace shouldn't
> matter...
>
> What you need to remember is that text strings are nodes in their own
> right. Nodes can be either textual, an element, or an attribute. The
> fragment above could be represented in a tree:
>
> Root Node (/)
>    \---	element P
> 	|-- #text = "For a vector..."
> 	|-- element VERB
> 	|	\--- #text = "x"
> 	|-- #text = ","
> 	|-- element VERB
> 	|	\--- #text = "y = sum(x)"
> 	|-- #text = "returns in the ..."
> 		.
> 		.
> 		.
>
> and so on. Hopefully this makes it a little clearer? Shout if not :-)
>
> Chris...
>
> -- 
> \ Chris Johnson                 \ NP:
>  \ cej at nightwolf.org.uk          \
>   \ http://cej.nightwolf.org.uk/  \
>    \ http://redclaw.org.uk/        
> ~---------------------------------------
>
>
> _______________________________________________
> SlugBug mailing list
> SlugBug at email-lists.org
> http://www.email-lists.org/mailman/listinfo/slugbug



More information about the SlugBug mailing list