(xslt 1.0) How to replace the space with some string from all the text values in xml?

后端 未结 3 1957
北荒
北荒 2021-01-14 20:20

EDIT: [it started with character replacement and I ended up with discovering string replacements with help of Dimitre Novatchev and Rol

3条回答
  •  一生所求
    2021-01-14 21:00

    The solution to the "prety-printed xml" is not really a solution.

    Imagine having a document like this:

    
     
      O M G
      D I Y
     
    
    

    The output from the currently accepted solution (after wrapping it in an and adding the identity rule is:

    
    %20
    %20%20O$M$G
    %20%20D$I$Y
    %20
    
    

    Now, why doesn't the proposed workaround save the situation? As we see from the above example, an element can have more than one child element that has text nodes...

    What is the real solution?

    The creators of XSLT have thought about this problem. Using the right terminology, we want all insignificant white-space-only text nodes to be ignored by the XSLT processor, as if they were not part of the document tree at all. This is achieved by the instruction.

    Just add this at a global level (as a child of and, for readability, before any templates):

     
    

    and now you really have a working solution.

提交回复
热议问题