You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何XSLT转换GLEIF XML无输出?寻求技术帮助

Why Your XSLT Isn't Producing Output (And How to Fix It)

Hey there, let's break down why your transformation isn't working—there are two critical issues that are preventing your XSLT from matching any nodes in your XML:

1. Missing Namespace Declaration

Your source XML uses the lei namespace (xmlns:lei="http://www.leiroc.org/data/schema/leidata/2014"), but your XSLT doesn't include this namespace binding. Without declaring it, the XSLT processor has no idea what lei: nodes you're referring to, so it can't find any matches at all.

2. Incorrect Node Paths

Your XSLT uses underscore-separated names like lei_LEIData and lei_LEIRecords, but your XML uses colon-separated namespace-prefixed names (lei:LEIData, lei:LEIRecords). These are not interchangeable—you need to use the namespace prefix (with a colon) in your XSLT paths, not underscores.

Additionally, there's one small typo in your path: lei_LegalForm/lei_EntityStatus should be lei:Entity/lei:EntityStatus (since EntityStatus is a direct child of Entity, not LegalForm).


Fixed XSLT Code

Here's the corrected version of your XSLT that addresses all these issues:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:lei="http://www.leiroc.org/data/schema/leidata/2014"
                version="1.0">
  <xsl:output method="xml" indent="yes"/>
  
  <xsl:template match="/">
    <lei_LEIData>
      <lei_LEIRecords>
        <xsl:apply-templates select="lei:LEIData/lei:LEIRecords/lei:LEIRecord"/>
      </lei_LEIRecords>
    </lei_LEIData>
  </xsl:template>
  
  <xsl:template match="lei:LEIData/lei:LEIRecords/lei:LEIRecord">
    <lei_LEIRecord>
      <xsl:for-each select="lei:LEI|
                            lei:Entity/lei:LegalName|
                            lei:Entity/lei:BusinessRegisterEntityID|
                            lei:Entity/lei:LegalJurisdiction|
                            lei:Entity/lei:LegalForm|
                            lei:Entity/lei:EntityStatus|
                            lei:Registration/lei:InitialRegistrationDate|
                            lei:Registration/lei:LastUpdateDate|
                            lei:Registration/lei:RegistrationStatus|
                            lei:Registration/lei:NextRenewalDate|
                            lei:Registration/lei:ManagingLOU|
                            lei:Registration/lei:ValidationSources">
        <xsl:attribute name="{local-name()}">
          <xsl:value-of select="text()"/>
        </xsl:attribute>
      </xsl:for-each>
      
      <xsl:for-each select="lei:Entity/lei:BusinessRegisterEntityID/@register">
        <xsl:attribute name="register">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:for-each>
      
      <xsl:for-each select="lei:Entity/lei:LegalAddress/lei:Line1|
                            lei:Entity/lei:LegalAddress/lei:City|
                            lei:Entity/lei:LegalAddress/lei:Country|
                            lei:Entity/lei:LegalAddress/lei:PostalCode">
        <xsl:attribute name="legaladdress_{local-name()}">
          <xsl:value-of select="text()"/>
        </xsl:attribute>
      </xsl:for-each>
      
      <xsl:for-each select="lei:Entity/lei:HeadquartersAddress/lei:Line1|
                            lei:Entity/lei:HeadquartersAddress/lei:City|
                            lei:Entity/lei:HeadquartersAddress/lei:Country|
                            lei:Entity/lei:HeadquartersAddress/lei:PostalCode">
        <xsl:attribute name="headquarter_{local-name()}">
          <xsl:value-of select="text()"/>
        </xsl:attribute>
      </xsl:for-each>
    </lei_LEIRecord>
  </xsl:template>
</xsl:stylesheet>

Key Changes Made:

  • Added the lei namespace declaration to the <xsl:stylesheet> element so the processor recognizes the prefix
  • Updated all node paths to use lei: prefix instead of underscores to match your XML structure
  • Fixed the typo in the EntityStatus path to point to the correct parent node
  • Used local-name() instead of name() in attribute names to avoid including the namespace prefix in your output attributes (keeping your desired clean attribute names like LEI instead of lei:LEI)

When you run this corrected XSLT against your XML, you'll get the expected output with all the requested fields as attributes on the <lei_LEIRecord> element.

内容的提问来源于stack exchange,提问作者J.Farlov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:20:57