Style inline text along with nested tags with XSLT

↘锁芯ラ 提交于 2019-12-11 20:10:10

问题


I have an XML structure that looks something like this.

<root>

  <outer-tag>
    Some Text
    <inner-tag> Some more text </inner-tag>
    finally some more text
  </outer-tag>

  <outer-tag>
    ....
  </outer-tag>

  ...
</root>

How would the XSLT look like for the above structure?

I am doing something like this, which I know is wrong.

<xsl:for-each select="outer-tag">
    <xsl:value-of select="."/>
    <b><xsl:value-of select="inner-tag"/></b>
</xsl:for-each>

And the output for this XSLT looks like

Some text Some more text finally some more text <b>Some more text</b>

My actual output should be

Some text <b>Some more text</b> finally some more text 

Thanks in advance for your help.


回答1:


Use push style processing with template matching and apply-templates e.g.

<xsl:template match="inner-tag">
   <b>
     <xsl:apply-templates/>
   </b>
</xsl:template>

then the default templates would take care of making sure the processing is kept up or you can write your own doing that with e.g.

<xsl:template match="outer-tag">
  <div>
    <xsl:apply-templates/>
  </div>
</xsl:template>


来源:https://stackoverflow.com/questions/26991398/style-inline-text-along-with-nested-tags-with-xslt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!