XSLT连接空值

时间:2014-07-08 09:01:26

标签: xslt xslt-2.0 is-empty

我们要求我们列出传入xml中的所有空值。我已经搜索了但是我能找到的只是列出非空值,试图使用它来为我们的xml不返回所需的结果。

这是我们将收到的xml,我希望能够连接此xml和print中的所有空值。请帮助。

<?xml version = "1.0" encoding = "UTF-8"?>
<Output>
<Rows>
    <ns0:I2NA xmlns:ns0 = "http://www.example.com/schemas/Schema.xsd">
        <ns0:Organization>108</ns0:Organization>
        <ns0:AccountNumber>1231231231231231233 </ns0:AccountNumber>
        <ns0:Status>0</ns0:Status>
        <ns0:VipStatus>0</ns0:VipStatus>
        <ns0:TypeOfIdNo>1</ns0:TypeOfIdNo>
        <ns0:IdNo>2303111450               </ns0:IdNo>
        <ns0:HomePhone>123456              </ns0:HomePhone>
        <ns0:Employer>                                        </ns0:Employer>
        <ns0:EmployersPhone>123456              </ns0:EmployersPhone>
        <ns0:FaxPhone>123456              </ns0:FaxPhone>
        <ns0:MobileNo>0568520421          </ns0:MobileNo>
        <ns0:CountryCode>   </ns0:CountryCode>
        <ns0:PostalCode>          </ns0:PostalCode>
        <ns0:Position>    </ns0:Position>
        <ns0:MaritalStatus>0</ns0:MaritalStatus>
        <ns0:DateOfBirth>00000000</ns0:DateOfBirth>
        <ns0:EmailAddrs>                                                            </ns0:EmailAddrs>
        <ns0:UserCode1>  </ns0:UserCode1>
        <ns0:NationalityCode>   </ns0:NationalityCode>
        <ns0:NameLine1>ABC     </ns0:NameLine1>
        <ns0:NameLine2>                                        </ns0:NameLine2>
        <ns0:NameLine3>                                        </ns0:NameLine3>
        <ns0:ChDob>        </ns0:ChDob>
        <ns0:AddressLine1>USA                                   </ns0:AddressLine1>
        <ns0:AddressLine2>USA                                   </ns0:AddressLine2>
        <ns0:AddressLine3>USA                                   </ns0:AddressLine3>
        <ns0:AddressLine4>USA                                   </ns0:AddressLine4>
        <ns0:City>                              </ns0:City>
        <ns0:State>   </ns0:State>
        <ns0:GenderCode>0</ns0:GenderCode>
        <ns0:StatementNotifIndi> </ns0:StatementNotifIndi>
        <ns0:Nationality>                    </ns0:Nationality>
        <ns0:County>                              </ns0:County>
        <ns0:LastName>John                             </ns0:LastName>
        <ns0:MiddleName>                                        </ns0:MiddleName>
        <ns0:FirstName>SHAN MATHEW                             </ns0:FirstName>
        <ns0:LangPref>   </ns0:LangPref>
    </ns0:I2NA>
</Rows>
<EOF>true</EOF>

当应用XSLT时,我们希望收到以下字符串作为输出。

Status,Employer,CountryCode,PostalCode,Position,EmailAddrs,UserCode1,NationalityCode,NameLine2,NameLine3,ChDob,City,State,StatementNotifIndi,Nationality,County,MiddleName,LangPref

谢谢!

1 个答案:

答案 0 :(得分:2)

使用<xsl:value-of select="//*[not(*) and not(normalize-space())]/local-name()" separator=","/>。但我不明白为什么您的示例字符串以Status开头,而XML的字段值为<ns0:Status>0</ns0:Status>

使用XSLT 1.0,您需要更多代码:

<xsl:for-each select="//*[not(*) and not(normalize-space())]">
  <xsl:if test="position() > 1"><xsl:text>.</xsl:text></xsl:if>
  <xsl:value-of select="local-name()"/>
</xsl:for-each>