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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:53:58+00:00 2026-05-11T16:53:58+00:00

is it possible to access a query string using xslt? i have a url

  • 0

is it possible to access a query string using xslt?

i have a url e.g

http://www.example.com/page.aspx?k=aa&lang=en

I want to do something like

if lang = en

<div>displaly stuff</div>

else

 <div>display other stuff</div>

can you show me how to do this using xslt?

  • 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-11T16:53:58+00:00Added an answer on May 11, 2026 at 4:53 pm

    is it possible to access a query
    string using xslt?

    Yes, if the query string is passed as a parameter.

    The code below shows that no extension function is required to access a query-string. It can be passed as a (global) parameter. This is to be preferred as it reduces the need for extensions and results in cleaner and more readable code.

    Then one can perform tokenization (with the tokenize() function in XSLT 2.0 or in XSLT 1.0 using the str-split-to-words template of FXSL 1.x or a self-written recursive tokenization template.)

    XSLT 1.0 solution:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common"
    >
    
       <xsl:import href="strSplit-to-Words.xsl"/>
    
       <xsl:output indent="yes" omit-xml-declaration="yes"/>
         <xsl:param name="pQString" select=
         "'?login=userId&amp;tag=XSLT&amp;lang=en&amp;level=expert'"
         />
    
    
        <xsl:template match="/">
        <xsl:variable name="vwordNodes">
          <xsl:call-template name="str-split-to-words">
            <xsl:with-param name="pStr" select="$pQString"/>
            <xsl:with-param name="pDelimiters" 
                      select="'?&amp;'"/>
          </xsl:call-template>
        </xsl:variable>
    
        <xsl:variable name="vLang" select=
          "substring-after(ext:node-set($vwordNodes)/*
                                 [starts-with(.,'lang=')]
                                   [last()],
                           'lang='
                          )
          "/>
    
          <xsl:value-of select="concat('lang = ', $vLang)"/>
        </xsl:template>
    </xsl:stylesheet>
    

    when the above transformation is applied on any XML document (will not be used), the wanted result is produced:

    lang = en
    

    Do note the use of the FXSL 1.x str-split-to-words template and the use of the EXSLT ext:node-set() extension function.

    XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
       <xsl:output indent="yes" omit-xml-declaration="yes"/>
    
         <xsl:param name="pQString" as="xs:string" select=
         "'?login=userId&amp;tag=XSLT&amp;lang=en&amp;level=expert'"
         />
    
        <xsl:template match="/">
          <xsl:variable name="vLang" as="xs:string" select=
          "substring-after(
                           tokenize($pQString, '\?|&amp;')
                                     [starts-with(.,'lang=')]
                                        [last()],
    
                           'lang='
                           )
          "/>
    
          lang = "<xsl:sequence select='$vLang'/>"
        </xsl:template>
    </xsl:stylesheet>
    

    When the above XSLT 2.0 transformation is performed, it produces the correct result:

      lang = "en"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since someone else is having the same problem, I'm guessing… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer yield return works for exactly 4 cases: IEnumerable IEnumerable<T> IEnumerator… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer If you don't mind being tied to Microsoft implementation you… May 11, 2026 at 11:31 pm

Related Questions

This problem has been solved thanks to your suggestions. See the bottom for details.
OK so whenever anyone hits our site who is not logged in, it pushes
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a
I'm playing around at the start of a personal project in C# and MySQL.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.