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 6659951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:05:39+00:00 2026-05-26T02:05:39+00:00

I am trying to add anchors to my html output. The html is created

  • 0

I am trying to add anchors to my html output. The html is created using xsl 2.0 to transform xml to html. I need to be able to pass a list of regular expressions into my style sheet and have every matching instance of the list of regex be made into an anchor. I have code that works for a single regex, but when I run the list of regex through i get multiples of the same paragraph. I am by no means an expert of xsl 2.0. I’m not sure it’s possible to do it this way. I can use c# too, if that’s easier. if anyone thinks that would be a better solution though im not sure it is.

The Code that works for a single regex is:

<xsl:template match="text()" mode="content">
    <xsl:variable name="text">
        <xsl:value-of select="."></xsl:value-of>
    </xsl:variable>
    <!--
        IndexTerms is a parameter passed into the sheet it is a list of regex expressions seperated by semi colons
    -->
    <xsl:for-each select="tokenize($IndexTerms, ';')">
        <xsl:call-template name="IndexTerm">
            <xsl:with-param name="matchedRegex">
                <xsl:text>(.*)(</xsl:text>
                <xsl:value-of select="."></xsl:value-of>
                <xsl:text>)(.*)</xsl:text>
            </xsl:with-param>
            <xsl:with-param name="text">
                <xsl:value-of select="$text"></xsl:value-of>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:for-each>
</xsl:template>

<xsl:template name="IndexTerm">
    <xsl:param name="matchedRegex">
        <xsl:text>asdf</xsl:text>
    </xsl:param>
    <xsl:param name="text"></xsl:param>
    <xsl:analyze-string select="$text" regex="{$matchedRegex}" flags="m">
        <xsl:matching-substring>
            <xsl:call-template name="IndexTerm">
                <xsl:with-param name="text">
                    <xsl:value-of select="regex-group(1)"></xsl:value-of>
                </xsl:with-param>
                <xsl:with-param name="matchedRegex">
                    <xsl:value-of select="$matchedRegex"></xsl:value-of>
                </xsl:with-param>
            </xsl:call-template>
                <xsl:element name="a">
                    <xsl:attribute name="class">
                        <xsl:text>IndexAnchor</xsl:text>
                    </xsl:attribute>
                    <xsl:value-of select="regex-group(2)"></xsl:value-of>
                </xsl:element>
                <xsl:value-of select="regex-group(3)"></xsl:value-of>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:value-of select="."></xsl:value-of>
        </xsl:non-matching-substring>
    </xsl:analyze-string>
</xsl:template>

Sample Input:

<body>
<sec sec-type="intro">
    <title>INTRODUCTION</title>
    <p>Digital Television is the most advanced version of Television
        technology improved in the last century. Digital TV provides
        customers more choices and interactivity. New technology called
        Internet Protocol-based Television (IPTV) uses digital TV technology
        and transmits it over IP based networks (Driscol, 2008),
            (<xref ref-type="bibr" rid="r15">Moawad, 2008</xref>). IPTV is a
        technique that transmits TV and video content over a network that
        uses the IP networking protocol. With increasing the number of
        users, performance becomes more important in order to provide
        interest in video content applications and relative services. The
        requirement for new video applications on traditional broadcast
        networks (cable, terrestrial transmitters, and satellite) opens a
        new perspective for the developed use of IP networks to satisfy the
        new service demands (Driscol,
        2008</p>
    <sec>
        <title>More Introducing</title>
        <p>Internet Protocol Television, IPTV, Telco TV, or broadband TV is
            delivering high quality broadcast television and/or on-demand video
            and audio content over a broadband network. On the other hand, IPTV
            is a mechanism applied to deliver old TV channels, movies, and
            video-on-demand contents over a private network. The official
            definition approved by the International Telecommunication Union
            focus group on IPTV (ITU-T FG IPTV) is as: &#x201C;IPTV is
            defined as multimedia services such as
            television/video/audio/text/graphics /data delivered over IP based
            networks managed to provide the required level of quality of service
            and experience, security, interactivity and reliability&#x201D;
            (Driscol, 2008,
            pp.2).</p>
    </sec>
</sec>

Sample Output using the Regex Input “Digital Televisions?;Internet” would be:

<body>
<h1>INTRODUCTION</h1>
<p><a class="IndexAnchor">Digital Television</a> is the most advanced version of Television
    technology improved in the last century. Digital TV provides
    customers more choices and interactivity. New technology called
    <a class="IndexAnchor">Internet</a> Protocol-based Television (IPTV) uses digital TV technology
    and transmits it over IP based networks (Driscol, 2008),
        (Moawad, 2008). IPTV is a
    technique that transmits TV and video content over a network that
    uses the IP networking protocol. With increasing the number of
    users, performance becomes more important in order to provide
    interest in video content applications and relative services. The
    requirement for new video applications on traditional broadcast
    networks (cable, terrestrial transmitters, and satellite) opens a
    new perspective for the developed use of IP networks to satisfy the
    new service demands (Driscol,
    2008</p>
<h2>More Introducing</h2>
    <p><a class="IndexAnchor">Internet</a> Protocol Television, IPTV, Telco TV, or broadband TV is
        delivering high quality broadcast television and/or on-demand video
        and audio content over a broadband network. On the other hand, IPTV
        is a mechanism applied to deliver old TV channels, movies, and
        video-on-demand contents over a private network. The official
        definition approved by the International Telecommunication Union
        focus group on IPTV (ITU-T FG IPTV) is as: &#x201C;IPTV is
        defined as multimedia services such as
        television/video/audio/text/graphics /data delivered over IP based
        networks managed to provide the required level of quality of service
        and experience, security, interactivity and reliability&#x201D;
        (Driscol, 2008,
        pp.2).</p>

  • 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-05-26T02:05:40+00:00Added an answer on May 26, 2026 at 2:05 am

    Frankly instead of separating the different patterns by a semicolon I would strongly suggest to use the bar “|” which is the regular expression language character for separating alternatives. Then you can simply feed that complete parameter to analyze-string:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      version="2.0"
      exclude-result-prefixes="xs">
    
      <xsl:param name="patterns" as="xs:string" select="'Digital Televisions?|Internet'"/>
    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@*, node()"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="text()">
        <xsl:analyze-string select="." regex="{$patterns}">
          <xsl:matching-substring>
            <a class="IndexAnchor">
              <xsl:value-of select="."/>
            </a>
          </xsl:matching-substring>
          <xsl:non-matching-substring>
            <xsl:value-of select="."/>
          </xsl:non-matching-substring>
        </xsl:analyze-string>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Does that help? If you need to convert your semicolon separated list to the bar separated then do e.g. <xsl:param name="patterns" as="xs:string" select="string-join(tokenize($yourParam, ';'), '|')"/>.

    I have not used a mode and have not looked at any other transformation you might want to do but of course you should be able to use the template I have presented with a mode if needed.

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

Sidebar

Related Questions

I'm trying to add anchors to all h2's in my html, using python. This
I am trying to add a html snippet dynamically which contains named anchors and
Trying to add a class object into a List using reflection, but when invoking
I am trying to add horizontal scroll bar in a JComboBox using reference with
I am trying to create a proper regular expression to find all anchors in
I'm using the cycle plugin and I'm trying to add an overlay on top
I am trying to add an HTML link with an image as the anchor,
I'm trying to add the target attribute to some anchors when a radio button
Trying to add a 'box' to a form at design time, I looked up
Trying to add email notification to my app in the cleanest way possible. When

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.