Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

given the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <report>
    <![CDATA[<?xml version="1.0" encoding="UTF-8"?><whatever><title>GREETING</title><greeting>Hi</greeting><name>Dave</name></whatever>]]>
  </report>
</root>

How can I use XSL-T to take into account this "embedded" XML?

An example output I would want to get after XSL-Transformations is like this:

<?xml version="1.0" encoding="UTF-8"?>
<TransformedRoot>
  <data><html><head><title>GREETING</title></head><body><p>Hi, Dave!</p></body></html>
</TransformedRoot>

Assuming this is the standard XSL-T I am using:

<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
    <xsl:template match="/root">
        <TransformedRoot>
           <data><!-- How do I get the elements here? --></data>
        </TransformedRoot>            
    </xsl:template>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

With commercial editions of Saxon 9:

<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
    <xsl:template match="/root">
        <TransformedRoot>
           <data>
             <xsl:apply-templates/>
           </data>
        </TransformedRoot>            
    </xsl:template>

<xsl:template match="report">
  <xsl:apply-templates select="saxon:parse(normalize-space(.))/node()"/>
</xsl:template>

<xsl:template match="whatever">
  <html>
     <head>
        <xsl:copy-of select="title"/>
      </head>
      <body>
        <p>
         <xsl:apply-templates/>
        </p>
      </body>
  </html>
</xsl:template>

<xsl:template match="greeting">
  <xsl:value-of select="concat(., ', ')"/>
</xsl:template>

<xsl:template match="name">
  <xsl:value-of select="concat(., '!')"/>
</xsl:template>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...