Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    TNO
    TNO is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    213
    Thanks
    2
    Thanked 1 Time in 1 Post

    Placing a result in two locations

    In my XML file I have a custom tag:

    Code:
    <TNO:FOO />
    My XSL transforms it into something like this:

    Code:
    <xsl:template match="TNO:FOO">
       <script type="text/javascript">
         var badPractice = true;
       </script>
       <div id="title">
          <xsl:value-of select="./@text"/>
       </div>
    </xsl:template>
    The problem with this is obvious..I'll have <script> blocks all over the body where they shouldn't be. How would I go about getting that script tag into the head or manipulating a script tag that already exists there? Is it possible to manipulate a transformation during the transformation?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by TNO View Post
    In my XML file I have a custom tag:

    Code:
    <TNO:FOO />
    My XSL transforms it into something like this:

    Code:
    <xsl:template match="TNO:FOO">
       <script type="text/javascript">
         var badPractice = true;
       </script>
       <div id="title">
          <xsl:value-of select="./@text"/>
       </div>
    </xsl:template>
    The problem with this is obvious..I'll have <script> blocks all over the body where they shouldn't be. How would I go about getting that script tag into the head or manipulating a script tag that already exists there? Is it possible to manipulate a transformation during the transformation?
    this is the result of a bad designed stylesheet. what you ask is possible but will add a new useless complication. My suggestion is to redesign the stylesheet if you can. Just move the script blocks and add conditionals in the proper template.

    regards

  • #3
    TNO
    TNO is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    213
    Thanks
    2
    Thanked 1 Time in 1 Post
    After some more thought I've settled on parsing into an xsl variable as an intermediate step, then applying a template to that variable. Thanks for the advice


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •