Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:22:54+00:00 2026-06-12T04:22:54+00:00

I have some design issues in my xslt engine. Quickly, I’m transforming XML documents

  • 0

I have some design issues in my xslt engine.
Quickly, I’m transforming XML documents in other XML documents (first is a metamodel, second is OpenDocument XML).

At one point, I want to output the content text node of an element based upon some conditions.
let’s use a dummy example :

<father haircolor='blond'>
    <son>
        some text
    </son>
    <sister>
        some stupid text
    </sister>
</father>

And I want to output the text node of <son> element if its parent is a ‘blond father’ and if it got a sister following

I have different solutions for this :

First is using precise patterns :

<xsl:template match="father[haircolor='blond']>...</xsl:template>

<xsl:template match="son[following-sibling::sister]>...</xsl:template>

Second is using mode attribute in templates :

<xsl:template match="father[haircolor='blond' and son and sister]">
    <xsl:apply-template select='*' mode='ConditionsAreOk'/>
</xsl:template>

Third is using a xsl:if in the leaf template :

<xsl:template match="son">
    <xsl:if test="parent::father/@haircolor = 'blond' and following-sibling::sister>
         {.}
    </xsl:if>
</xsl:template>

As I’m concerned with the readability and maintenability of my xslt code, I’d like to chose the best way.
To be clear, I don’t ask for help about ‘how to’, but ‘Which way is the best’.

My actual thoughts :
I think first way is the most pure XSLT but could be quite hard-core when conditions is complicated and on several elements. I will have to create several specific templates.
I have preference for the last one, because instead of several templates with specific matchs, i have just one with hardcore XPaths in the xsl:if test condition. It’s less code and less documentation (but yes, you have to document the XPath or you’ll forgot about it in 5 minutes…).

Any opinions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:22:56+00:00Added an answer on June 12, 2026 at 4:22 am

    I strongly recommend to avoid as much as possible explicit conditional instructions and to use template match patterns instead.

    In this particular case I’d use:

    <xsl:template match="father[haircolor='blond']/son[following-sibling::sister]>
      <!-- your code here -->
    </xsl:template>
    

    So, it is just one single template — not two — and the code inside the template body has got rid of difficult to read, understand and maintain conditional instructions.

    My own principle is:

    If the code contains explicit conditional instructions, then it definitely needs improvement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First up, i realize this application has some design issues and while rewriting a
I have some no so easy routing design issues with rails 3. We have
I'm setting up a Magento site and have some design requirements that we can't
Updated Problem solved, I have some design problem here. The directory looks like that:
I have some sort of a design problem with my Django AJAX application. I
I have some thoughts on the design of the commanding part in CQRS. I
I have some transitive dependencies in my database design. I have been told by
I have a problem trying to design some generic storage.. Basically I have the
I have an OS design project with some subprojects, I would like to try
I need some advice for a design which I have to implement in application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.