我想知道是否可以在 XSLT 中嵌套动态节点集,如果可以,如何使用 xPath 选择它们。这是一项更大任务的一部分。我只展示我坚持的部分。
这是我的 XSLT:
<xsl:variable name="Tables">
<xsl:for-each select="Table">
<xsl:variable name="TableName" select="Name | @Name"/>
<xsl:variable name="Columns">
<xsl:for-each select="Column">
<xsl:variable name="ColumnName" select="Name | @Name"/>
<xsl:variable name="Type" select="Type | @Type"/>
<Column>
<Name>
<xsl:value-of select="$ColumnName"/>
</Name>
<Type>
<xsl:value-of select="$Type"/>
</Type>
</Column>
</xsl:for-each>
</xsl:variable>
<Table>
<Name>
<xsl:value-of select="$TableName"/>
</Name>
<Columns>
<xsl:value-of select="$Columns"/>
</Columns>
</Table>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($Tables)/Table">
Table Name: <xsl:value-of select="Name"/>
<xsl:for-each select="msxsl:node-set(Columns)/Column" xml:space="preserve">
Column Name: <xsl:value-of select="Name"/>
Column Type: <xsl:value-of select="Type"/>
</xsl:for-each>
</xsl:for-each>
这是我的 XML:
<Table Name="Product">
<Column Name="ProductID" Type="int"/>
<Column Name="Name" Type="string"/>
<Column Name="Cost" Type="decimal"/>
<Column Name="Area" Type="decimal?"/>
</Table>
<Table Name="Market">
<Column Name="MarketID" Type="int"/>
<Column Name="Name" Type="string"/>
<Column Name="MinimumASP" Type="double"/>
<Column Name="MaximumASP" Type="double"/>
</Table>
这是我目前得到的输出:
Table Name: Product
Table Name: Market
这就是我想要得到的:
Table Name: Product
Column Name: ProductID
Column Type: int
Column Name: Name
Column Type: string
Column Name: Cost
Column Type: decimal
Column Name: Area
Column Type: decimal?
Table Name: Market
Column Name: MarketID
Column Type: int
Column Name: Name
Column Type: string
Column Name: MinimumASP
Column Type: double
Column Name: MaximumASP
Column Type: double