Menu

Selecting XSL at runtime

Help
Bob C
2005-02-17
2013-04-16
  • Bob C

    Bob C - 2005-02-17

    I need to select a stylesheet at runtime based on an attribute in the input XML document. Outside of Babeldoc, I would write a SAX content handler to pick out the attribute I'm looking for, then use that to select a stylesheet.

    To be able to apply a particular stylesheet at runtime in Babeldoc, would I need to integrate custom code into a pipeline?

     
    • Sherman Wood

      Sherman Wood - 2005-02-17

      I would try using a Router or XPathExtract stage to set a document variable that is the stylesheet name, and then having the XSLTransform stage use the contents of the document variable as the stylesheet name.

      Sherman

       
    • Bob C

      Bob C - 2005-02-17

      I will have up to twenty stylesheets. Based on the value of the attribute, I would select one of the twenty stylesheets to apply. Right now I do this by loading a properties file where the key represents the attribute value and the value represents the stylesheet to apply. Can I apply this same logic within Babeldoc, or would I simply incorporate my current classes into a Babeldoc project?

       
    • Sherman Wood

      Sherman Wood - 2005-02-22

      You can do this in Babeldoc in the following way, but it is not pretty.

      1. XpathExtract the attribute into a document variable
      2. A Router step to test the variable and call one of a number of steps.
      3. These steps that set the right XSL file name in a document parameter.
      4. Transform step to run the selected transform using the document variable.

      It is probably simpler to have a custom stage that uses your properties file and does the right thing.

      Sherman

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.