devxlogo

Variable Length Ordered Lists Using XSL

Variable Length Ordered Lists Using XSL

Question:

I’m attempting to create an ordered list every time the Sequence attribute of a Para element has been set to ‘Begin’. The list should continue until it reaches a paragraph with the Sequence attribute set to ‘End’. The problem arises because the

    and
are not being properly matched within the XSL document. I have tried various combinations of
    , CData, and CDATA sections.

                
  1. Answer:

    This can be a real pain?I’ve run into similar situations, where you need to be able to wrap a tag around an expression but the tag start and tag end are generated programmatically (and hence appear “unbalanced” to the XSL document). The simplest solution (and it isn’t terribly simple), is to recognize that you need to abstract your structure out one level. What you have is this:

    First ParagraphSecond ParagraphThird ParagraphFourth ParagraphFifth ParagraphSixth Paragraph

    The problem with this code is that you’re actually subverting the intrinsic structure of the code, flattening the hierarchy too much. There is no clean way to write an XPath query that will satisfy this.However, if you recognized that each of these items exist in groups, then you could revamp your structure a bit:

       First Paragraph   Second Paragraph   Third Paragraph   Fourth Paragraph   Fifth Paragraph   Sixth Paragraph

    Then the XSL transform becomes much simpler:

        
  2. This actually brings up a good point to remember about XSL?in general, whenever you have an order issue involved (or, as in this example, you seem to have unbalanced elements), this is typically an indication that your hierarchy is too flat. By deepening the hierarchy, encapsulating it if you will, you can usually solve such problems.

    See also  5 Tips for Choosing the Right Medical Software for Your Practice
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist