Subject: [xsl] String replacement in included content From: Rush Manbert <rush@xxxxxxxxxxx> Date: Tue, 11 Oct 2005 11:57:52 -0700 |
I have written a DTD and a XSL stylesheet that extend XHTML. I parse the XHTML documents and apply the XSL transformations using libxml/libxslt, so I'm limited to using XSLT 1.0 and a few EXSLT extras.
As I said, all of this works at present. What I need to add now is handling of the tag attribute. The idea here is that when we include a component doc, we specify a text tag value that can be used within the included content. My first cut at this is to define a replacement text, %CT% (CT stands for Component Tag and the surrounding % symbols are for parsing.) that can appear anywhere in the component document that "free form" text is allowed. In general, this means attribute contents. My application uses the contents of form action attributes and input name attributes to do client side scripting (Not Javascript embedded in the XHTML documents), so I need to be able to make them unique in order to lookup and call the right script methods.
A single level example: The including doc (simplified) ------------------------------ <head> </head> <body> <component tag="A" href="Component1.xhtm" /> <component tag="B" href="Component1.xhtm" /> </body>
The file Component1.xhtm: ------------------------ <head> </head> <body> <form action="%CT%_Component1Action" method="get"> <input type="submit" name="%CT%_Component1Submit" /> </form> </body>
The desired output: ------------------ <head> </head> <body> <form action="A_Component1Action" method="get"> <input type="submit" name="A_Component1Submit" /> </form> <form action="B_Component1Action" method="get"> <input type="submit" name="B_Component1Submit" /> </form> </body>
A multilevel example: The including doc (simplified) ------------------------------ <head> </head> <body> <form action="MyFormAction" method-"get"> <component tag="A" href="Component2.xhtm" /> </form> </body>
The file Component2.xhtm: ------------------------ <head> </head> <body> <input type="submit" name="Component2Submit_%CT%" /> <component tag="B_%CT%" href="Component3.xhtm" /> <component tag="C_%CT%" href="Component3.xhtm" /> </body>
The file Component3.xhtm: ------------------------ <head> </head> <body> <input type="submit" name="Component3Submit_%CT%" /> </body>
The desired output: ------------------ <head> </head> <body> <form action="MyFormAction" method-"get"> <input type="submit" name="Component2Submit_A" /> <input type="submit" name="Component3Submit_B_A" /> <input type="submit" name="Component3Submit_C_A" /> </form> </body>
NOTE that %CT% could appear in the middle of the strings as well, i.e. <input type="submit" name="Component1%CT%Submit" />
Since ant XHTML document may be used as a component, I must also allow for the case where we just parse and display a document that contains the special %CT% sequences, but there is no Component Tag defined. In that case the best outcome would be if I could just remove the instances of %CT%. So if my application were to just parse and transform Component1.xhtm as the top level document, the desired output would be: <head> </head> <body> <form action="_Component1Action" method="get"> <input type="submit" name="_Component1Submit" /> </form> </body>
</xsl:choose> </xsl:template>
As a first attempt, ignoring the stuff about replacing %CT% when there is no tag defined, I tried modifying this template to use the str:replace template available at www.exslt.org, but that has not worked out so well. If I could just treat the contents of the component file as a string for text replacement purposes, then turn it into a node set for use with xsl:apply-templates it seems like I would be partway there.
Thanks, Rush
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] display question with xsl:whe, Jignesh Shah | Thread | Re: [xsl] String replacement in inc, David Carlisle |
RE: [xsl] encoding on parameters fo, Michael Kay | Date | Re: [xsl] String replacement in inc, David Carlisle |
Month |