Retrieve page URL params or page URL in XSLT

前端 未结 4 1299
不知归路
不知归路 2021-01-14 13:37

I have a page which has URL structure : http://www.abc.com/xyz?parama=1¶mb=2

  • Is is possible to create a generic method for getting the values of an

4条回答
  •  长发绾君心
    2021-01-14 14:19

    Is is possible to get the URL of the page in XSL similar to javascript's location.href ?

    Not exactly in the same way, but yes, the query string can be passed as a parameter.

    Is is possible to create a generic method for getting the values of any additional params the URL maybe (parama=1¶mb=2)

    Yes, 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:

    
    
       
    
       
         
    
    
        
        
          
            
            
          
        
    
        
        
    
        
          
          
    
        
    
    

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

    parama=1
    paramb=2
    anyParamName=AnyValue
    

    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:

     
    
    
      
    
    

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

    parama=1
    paramb=2
    anyParamName=AnyValue
    

提交回复
热议问题