xml - XSLT ignores template for child element -


I am trying to convert XML to XML using XSLT:

HTML: < / P>

  & lt; Html & gt; & Lt; Body & gt; & Lt; P class = "one" & gt; Some paragraphs 1. & lt; / P & gt; & Lt; P class = "one" & gt; Some paragraphs 2. & lt; / P & gt; & Lt; P class = "one" & gt; Some paragraph 3 & lt; Em> Em & lt; / Em>. & Lt; / P & gt; & Lt; P class = "one" & gt; Some paragraphs 4. & lt; / P & gt; & Lt; P class = "one" & gt; Some paragraphs 5. & lt; / P & gt; & Lt; H3 & gt; Some title & lt; / H3 & gt; & Lt; P class = "two" & gt; Some other paragraph 1 & lt; Em> Em & lt; / Em>. & Lt; / P & gt; & Lt; P class = "two" & gt; Some other paragraphs 2. & lt; / P & gt; & Lt; P class = "two" & gt; Some other paragraph 3. & lt; / P & gt; & Lt; P class = "two" & gt; Some other paragraph 4. & lt; / P & gt; & Lt; P class = "two" & gt; Some other paragraphs 5. & lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

desired output:

  some paragraphs 1. Some paragraphs 2. Some paragraph 3 & lt; Emphasis & gt; Em & lt; / Emphasis & gt; with. Some paragraphs 4. Some paragraphs 5. Some titles & lt; Paragraphs & gt; Some other paragraph 1 & lt; Emphasis & gt; Em & lt; / Emphasis & gt; & Lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraphs 2. & lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraph 3. & lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraph 4. & lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraphs 5. & lt; / Paragraph & gt;  

XSLT:

  & lt; Xsl: Output Indent = "Yes" /> & lt; Xsl: template match = "/" & gt; & Lt; Xsl: Choose Apply-Template = "html / body" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "em" & gt; & Lt; Emphasis & gt; & Lt; Xsl: Select the value = "." / & Gt; & Lt; / Emphasis & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Match = "P [@ Class = 'Two']" & gt; & Lt; Paragraphs & gt; & Lt; Xsl: Select the value = "." / & Gt; & Lt; / Paragraph & gt; & Lt; / XSL: Templates & gt; Production of this XSLT tranformation:  
  some paragraphs 1. Some paragraphs 2. Some paragraphs 3 & lt; Emphasis & gt; He & lt; / Emphasis & gt; Some paragraphs 4. Some paragraphs 5. Some titles & lt; Paragraphs & gt; Some other paragraphs 1 am. & Lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraphs 2. & lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraph 3. & lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraph 4. & lt; / Paragraph & gt; & Lt; Paragraphs & gt; Some other paragraphs 5. & lt; / Paragraph & gt; The template works fine for  

em element when another template is defined for parent element ( p.one ) Is not done. However, when there is a template for the original element ( p.two ), ignore the template ( em ) element for the child and instead of receiving it by tran orphanation Given:

  & lt; Paragraphs & gt; & Lt; Emphasis & gt; Em & lt; / Emphasis & gt; & Lt; / Paragraph & gt; Any other paragraph 1 with;  

I see:

  & lt; Paragraphs & gt; With some other paragraph 1 & Lt; / Paragraph & gt;  

Why is XSLT ignoring the template for the em element in this case?

It is being ignored because you are printing this value only:

  & lt; Paragraphs & gt; & Lt; Xsl: value selection = "." // gt; & Lt; / Paragraph & gt;  

If you want to apply the em template to the content of the template, [ Should replace it with:

  & lt; Xsl: Template Match = "P [@ Class = 'Two']" & gt; & Lt; Paragraphs & gt; & Lt; Xsl: applied-template / & gt; & Lt; / Paragraph & gt; & Lt; / XSL: Templates & gt;  

Now will be processed in a template, if any (not only converted to text and it has been printed).


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -