[英]Getting key column in loop + XSLT
I need a help on getting primary key values repeated times from the xml.Here is the xml file. 我需要有关从xml重复获取主键值的帮助。这是xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<request id="test">
<dataSets>
<dataSet name="dim_table" friendlyName="dim" tableType="DIM">
<fields>
<field name="customer_id" dataType="varchar" primaryKey="true"/>
<field name="customer_name" dataType="VARCHAR" primaryKey="false"/>
<field name="customer_address" dataType="CHAR" primaryKey="false"/>
</fields>
</dataSet>
</dataSets>
</request>
the required output is 所需的输出是
KeycolumnName,Columnname KeycolumnName,列名
customer_id,customer_id customer_id,customer_id
customer_id,customer_name customer_id,customer_name
customer_id,customer_address customer_id,customer_address
Can anyone help me on this? 谁可以帮我这个事?
XML formatting is needed for a full answer, but: XML格式需要完整的答案,但是:
<xsl:template match="/dataSets/dataSet/fields">
<xsl:for-each select="field">
<xsl:value-of select="@name" />
</xsl:for-each>
</xsl:template>
(example code not tested) (示例代码未经测试)
Use XPath to define the content of the "select" attributes. 使用XPath定义“选择”属性的内容。
Reference: http://www.w3schools.com/xsl/el_for-each.asp 参考: http : //www.w3schools.com/xsl/el_for-each.asp
Updated code (previous answer couldn't handle this much new code): 更新了代码(以前的答案无法处理这么多新代码):
This code works for me: 该代码对我有用:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="//dataSet">
<xsl:for-each select="fields/field">
KeyColumnName="<xsl:value-of select="../field[@primaryKey='true']/@name" />" ColumnName="bar <xsl:value-of select="@name" />"
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.