Am trying to display XML content in an HTML using XSLT. Am using

<xsl:copy-of select = "childNode">
</xsl:copy-of>

When I used the above one, it will display the attribute as well.

<childNode>
<Team>
<TeamName>Team-A</TeamName>
</Team>
<Team>
<TeamName>Team-B</TeamName>
</Team>
<Team>
<TeamName>Team-C</TeamName>
</Team>
</childNode>

I don't want to display element.

有帮助吗?

解决方案

I don't see any attribute in your XML sample. If you only want to copy the contents of the childNode element then you can use <xsl:copy-of select="childNode/*"/> or perhaps better write a template

<xsl:template match="childNode">
  <xsl:copy-of select="*"/>
</xsl:template>

其他提示

Use xsl:copy instead of xsl:copy-of to copy just the selected node.

Use xsl:apply-templates to gain control over how child elements are handled through the definition of templates matching the children.

If you want to copy the childNode element along with its attributes and add some elements without going the (generally preferred) xsl:apply-templates route, try:

<xsl:copy select="childNode">
   <xsl:copy-of select="@*"/>
   <!-- add further content here as needed -->
</xsl:copy>

Possibilities abound but you'll have to clarify your question if none of these answers meet your needs.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top