Frage

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.

War es hilfreich?

Lösung

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>

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top