Removing Attributes from XSLT and working with result set

前端 未结 3 1806
渐次进展
渐次进展 2020-12-21 04:58

Is it possible to remove xml attributes from XSLT AND work with the resulting transform?

In other words, I have the following XML:



        
3条回答
  •  一整个雨季
    2020-12-21 05:31

    There is something odd in this question: I don't see how the title of your question does match the contents.

    In the title you are asking for a two-pass transform where the first pass must remove the attributes and the second must work on it.

    In the contents you show two templates which outputs the local name of the nodes and attributes and, after, you show in another template that you'd like to work with the attributes getting their value... :)

    As per @Dimitre's answer replied to the contents of your question (which does not address a real question I think) I will try to answer the title of your question, which seems much more interesting (and answerable).


    Removing Attributes from XSLT ...

    To remove the attributes (and obtain a transform without namespaces) you can work with an Identity Transformation. Because you want multi-pass you must copy the content of the transformation on a variable in the first pass.

    You can use modes to address the process to the elements in the first pass.

    ... and working with result set

    To work with result set (formally known as a result tree fragment) you need to apply the templates using a reference to the variable defined in the first pass. Welcome! This is the second pass :)

    Two pass transformation is relatively much accessible in XSLT 2.0 than in XSLT 1.0, because of the XSLT 2.0 ability to apply templates to an RTF. In XSLT 1.0 you will need a specific extension function called node-set().


    The XSLT 2.0 will look like this (pure example):

    
    
           
         
    
        
            
                
                    
                
            
    
            
        
    
        
            
                
            
        
    
        
            
        
    
     
    

    with results (applied on your input example)

    00
    

    The XSLT 1.0 will look very similar, but the transform root element:

    
    

    and the second pass:

     
    

提交回复
热议问题