如何在XSLT中识别启动节点



我的XML以下。

预期的TXT输出是:

stAddresscitystatezip
1Esd94587enamestAddrcitystatezip

我想制作一个通用的XSLT代码。因此,我想确定所有记录的子节点,并将其放入每个子节点的一行。

<rcrd>
  <Trans_rcrd>
     <stAdd>stAddress</stAdd>
     <city>city</city>
     <state>state</state>
     <zip>zip</zip>
  </Trans_rcrd>
  <Empler_rcrd>
     <rcrdID>1Esd</rcrdID>
     <empID>94587</empID>
     <eName>ename</eName>
     <stAdd>stAddr</stAdd>
     <city>city</city>
     <state>state</state>
     <zip>zip</zip>
  </Empler_rcrd>

如果"通用"表示元素名称的不可知论,那么您可以尝试

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output method="text"/>
<xsl:template match="/*/*">
    <xsl:value-of select="*" separator=""/>
    <xsl:text>&#10;</xsl:text>
</xsl:template>
</xsl:transform>

简单地处理根部元素的子元素并输出孙子的串联值

http://xsltransform.hikmatu.com/nbuy4kj

这可能会让您前进。在调试器中逐步了解它。

<xsl:template match="rcrd">
  <!-- Select the child nodes for each rcrd. -->
  <xsl:apply-templates select="*" mode="rcrdChildNodes"/>
</xsl:template>
<!-- This template will process the child nodes of rcrd. -->
<xsl:template match="*" mode="rcrdChildNodes">
  <xsl:apply-templates select="*" mode="outputChildNodes"/>
  <!-- Carriage return character. -->
  <xsl:text>&#13;</xsl:text>
</xsl:template>
<!-- Process the child nodes of Trans_rcrd and Empler_rcrd -->
<xsl:template match="*" mode="outputChildNodes">
  <xsl:value-of select="."/>
</xsl:template>
<xsl:template match="node()">
  <xsl:apply-templates/>
</xsl:template>

最新更新