Więc mam ten XML
<?xml version="1.0" encoding="utf-8"?>
<school name="AMU" location="CA">
<student name="Jonny">
<info age="20" class="A" />
</student>
</school>
To, co próbuję zrobić, to utworzyć tylko tabelę pomiędzy school
i student
,
<?xml version="1.0" encoding="utf-8"?>
<school name="AMU" location="CA">
<table>
.....
<table />
<student name="Jonny">
<info age="20" class="A" />
</student>
</school>
wiem jak stworzyć tabelę, której używam each-group
i concat
to.
Pracuję nad XSL,
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:template match="school">
<xsl:element name="school">
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:attribute name="location">
<xsl:value-of select="@location" />
</xsl:attribute>
<table>
created table
</table>
<xsl:copy>
<xsl:apply-templates select="student" />
</xsl:copy>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Mój problem polega na tym, że chcę skopiować wszystkie węzły poniżej mojej tabeli, aby mój wyjściowy XML miał tabelę między school
i student
i nic innego się nie zmieniło. (stół działa dobrze)
co powinienem zrobić?
Dzięki.
Odpowiedzi:
0 dla odpowiedzi № 1Po pierwsze, twój kod jest niepotrzebnie pełny. To:
<xsl:element name="school">
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:attribute name="location">
<xsl:value-of select="@location" />
</xsl:attribute>
można zastąpić tym:
<school name="{@name}" location="{@location}">
lub jeśli wolisz, przez
<xsl:copy>
<xsl:copy-of select="@*"/>
Następnie, jeśli chodzi o twoje pytanie, możesz zastąpić to:
<xsl:copy>
<xsl:apply-templates select="student" />
</xsl:copy>
przez to:
<xsl:copy-of select="student"/>