Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XSL tag matching

XSL tag matching

Scheduled Pinned Locked Moved XML / XSL
questiontoolsregexxmlhelp
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J Dunlap
    wrote on last edited by
    #1

    XSL I'm making some output be bold only if a certain condition is true:

    <xsl:if test="test"><b></xsl:if>

    Now the problem is, all end tags must directly match up with their start tags (i.e. you can't do "<b><i></b></i>" - you have to do "<b><i></i></b><i></i>"). But I'm wanting the "<b>" tag only to be outputted only if the test condition is true. Short of having seperate block for each combination of <b>, <i>, <u>, etc, how do I do it? I've thought of using script to concatenate a <b>:

    function GetTag(text)
    GetTag=Chr(60) + text + Chr(62)
    end function

    Or can someone show me a better way?

    "Do unto others as you would have them do unto you." - Jesus
    "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

    S 1 Reply Last reply
    0
    • J J Dunlap

      XSL I'm making some output be bold only if a certain condition is true:

      <xsl:if test="test"><b></xsl:if>

      Now the problem is, all end tags must directly match up with their start tags (i.e. you can't do "<b><i></b></i>" - you have to do "<b><i></i></b><i></i>"). But I'm wanting the "<b>" tag only to be outputted only if the test condition is true. Short of having seperate block for each combination of <b>, <i>, <u>, etc, how do I do it? I've thought of using script to concatenate a <b>:

      function GetTag(text)
      GetTag=Chr(60) + text + Chr(62)
      end function

      Or can someone show me a better way?

      "Do unto others as you would have them do unto you." - Jesus
      "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      The 'politically correct' way is probably to use the xsl:element tag e.g.

      xsl:choose
      <xsl:when test="test">
      <xsl:element name="b">
      Your Content
      </xsl:element>
      </xsl:when>
      xsl:otherwise
      Your Content
      </xsl:otherwise>
      </xsl:choose>

      This is easy enough if your content is in another rule or a function or something - not so easy otherwise...but it does make sure you've got all tags paired correctly. Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

      J P 2 Replies Last reply
      0
      • S Stuart Dootson

        The 'politically correct' way is probably to use the xsl:element tag e.g.

        xsl:choose
        <xsl:when test="test">
        <xsl:element name="b">
        Your Content
        </xsl:element>
        </xsl:when>
        xsl:otherwise
        Your Content
        </xsl:otherwise>
        </xsl:choose>

        This is easy enough if your content is in another rule or a function or something - not so easy otherwise...but it does make sure you've got all tags paired correctly. Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

        J Offline
        J Offline
        J Dunlap
        wrote on last edited by
        #3

        Stuart Dootson wrote: to use the xsl:element tag Now why didn't I remember that one! THANKS!!! :) :rose:

        "Do unto others as you would have them do unto you." - Jesus
        "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

        S 1 Reply Last reply
        0
        • J J Dunlap

          Stuart Dootson wrote: to use the xsl:element tag Now why didn't I remember that one! THANKS!!! :) :rose:

          "Do unto others as you would have them do unto you." - Jesus
          "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          And also remember xsl:attribute when you need to add attributes to elements :) Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

          J 1 Reply Last reply
          0
          • S Stuart Dootson

            And also remember xsl:attribute when you need to add attributes to elements :) Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

            J Offline
            J Offline
            J Dunlap
            wrote on last edited by
            #5

            Yep. You can bet I immediately looked up xsl:element and its related tags on MSDN as soon as I saw this! Thanks again!

            "Do unto others as you would have them do unto you." - Jesus
            "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

            1 Reply Last reply
            0
            • S Stuart Dootson

              The 'politically correct' way is probably to use the xsl:element tag e.g.

              xsl:choose
              <xsl:when test="test">
              <xsl:element name="b">
              Your Content
              </xsl:element>
              </xsl:when>
              xsl:otherwise
              Your Content
              </xsl:otherwise>
              </xsl:choose>

              This is easy enough if your content is in another rule or a function or something - not so easy otherwise...but it does make sure you've got all tags paired correctly. Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

              P Offline
              P Offline
              Philip Fitzsimons
              wrote on last edited by
              #6

              or even <xsl:choose> <xsl:when test="test"> <b>Your Content</b> </xsl:when> <xsl:otherwise>Your Content</xsl:otherwise></xsl:choose>


              "When the only tool you have is a hammer, a sore thumb you will have."

              S J 2 Replies Last reply
              0
              • P Philip Fitzsimons

                or even <xsl:choose> <xsl:when test="test"> <b>Your Content</b> </xsl:when> <xsl:otherwise>Your Content</xsl:otherwise></xsl:choose>


                "When the only tool you have is a hammer, a sore thumb you will have."

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #7

                I did say 'the politically correct way'....;P Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'

                1 Reply Last reply
                0
                • P Philip Fitzsimons

                  or even <xsl:choose> <xsl:when test="test"> <b>Your Content</b> </xsl:when> <xsl:otherwise>Your Content</xsl:otherwise></xsl:choose>


                  "When the only tool you have is a hammer, a sore thumb you will have."

                  J Offline
                  J Offline
                  J Dunlap
                  wrote on last edited by
                  #8

                  This is precicsely what I was trying to avoid. ;)

                  "Do unto others as you would have them do unto you." - Jesus
                  "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                  P 1 Reply Last reply
                  0
                  • J J Dunlap

                    This is precicsely what I was trying to avoid. ;)

                    "Do unto others as you would have them do unto you." - Jesus
                    "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                    P Offline
                    P Offline
                    Philip Fitzsimons
                    wrote on last edited by
                    #9

                    an even better way would be (xhtml & css2): <span>    <xsl:if test="test">       <xsl:attribute name="style">font-weight: bold</xsl:attribute>    </xsl:if>    Your Content </span> hope this helps


                    "When the only tool you have is a hammer, a sore thumb you will have."

                    J 1 Reply Last reply
                    0
                    • P Philip Fitzsimons

                      an even better way would be (xhtml & css2): <span>    <xsl:if test="test">       <xsl:attribute name="style">font-weight: bold</xsl:attribute>    </xsl:if>    Your Content </span> hope this helps


                      "When the only tool you have is a hammer, a sore thumb you will have."

                      J Offline
                      J Offline
                      J Dunlap
                      wrote on last edited by
                      #10

                      Yep. That's what I'm doing. Thanks!

                      "Do unto others as you would have them do unto you." - Jesus
                      "An eye for an eye only makes the whole world blind." - Mahatma Gandhi

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups