开发者

XSL: Tracking elements that toggle

The following string gets encoded in my source XML using toggles, and I want it changed to nodes with formatting information. (This is XLIFF to WordprocessingML.)

"Text, bold text, bold and italics text, bold text, plain text."

Source XML:

<text>
Text  
<format id="1" type="bold" />
bold text,  
<format id="2" type="italics" /> 
bold and italics text,
<endformat id="2" />
bold text,
<endformat id="1" />
plain text.
</text>

I need:

<run>
   <format></format>
   <text>Text, </text>
</run>
<run>
   <format><b/></format>
   <text>bold text, </run>
</run>
<run>
   <format><b/><i/></format>
   <text>bold and italics text, </run>
</run>
<run>
   <format><b/></format>
   <text>bold te开发者_运维问答xt, </run>
</run>
<run>
   <format></format>
   <text>plain text.</run>
</run>

If I were using a procedural language, I'd keep a running record of what formatting is active and write out the <format> element accordingly.

But how do I do it in XSL?


Since the child nodes of text are alternating text() followed by format with symmetric endformat and text() I think you can pass a list of the nodes to xsl:call-template recursively, processing two start nodes and 2 end nodes and shortening the list by the leading 2 nodes and traling 2 nodes each time. But I am not clear about the syntax of your file so this may not be possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜