【问题标题】:XSL Transform for-each not matchingXSL 转换 for-each 不匹配
【发布时间】:2023-01-11 04:33:28
【问题描述】:

我正在处理 XML 转换,以将传入的 XML 从旧格式迁移到新格式。出于某种原因,<xsl:for-each> 与 XML 不匹配,我无法弄清楚原因。我的假设是它与记录和记录元素上的命名空间有关。

我的 XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="https://github.com/rSmart/ce-tech-docs/tree/master/v2_0"
                exclude-result-prefixes="h">
  <xsl:output method="xml" indent="yes" />
  <xsl:template match="/">
    <hrmanifest xmlns="https://github.com/KualiCo/ce-tech-docs/tree/master/v3_0" schemaVersion="3.0">
      <xsl:attribute name="statusEmailRecipient"><xsl:value-of
          select="/*/@statusEmailRecipient"></xsl:value-of></xsl:attribute>
      <xsl:attribute
        name="recordCount"><xsl:value-of select="/*/@recordCount"></xsl:value-of></xsl:attribute>
      <h:records xmlns:h="https://github.com/KualiCo/ce-tech-docs/tree/master/v3_0">
        <xsl:for-each select="hrmanifest/h:records/h:record">
          <record>
            Text
          </record>
        </xsl:for-each>
      </h:records>
    </hrmanifest>
  </xsl:template>
</xsl:stylesheet>

我的示例 XML,其中一些值已编辑,因为此时甚至还没有涉及到这些值:

<?xml version='1.0' encoding='UTF-8'?>
<hrmanifest xmlns="https://github.com/rSmart/ce-tech-docs/tree/master/v2_0" schemaVersion="2.0"
  statusEmailRecipient="[REDACTED]" recordCount="20594">
  <h:records xmlns:h="https://github.com/rSmart/ce-tech-docs/tree/master/v2_0">
    <h:record principalId="[REDACTED]" principalName="[REDACTED]" active="true">
      <h:affiliations>
        <h:affiliation affiliationType="[REDACTED]" campus="[REDACTED]" default="true" active="true">
          <h:employment employeeStatus="[REDACTED]" employeeType="[REDACTED]" baseSalaryAmount="[REDACTED]"
            primaryDepartment="[REDACTED]" employeeId="[REDACTED]" />
        </h:affiliation>
      </h:affiliations>
      <h:addresses>
        <h:address addressTypeCode="WRK" addressLine1="[REDACTED]" city="[REDACTED]"
          stateOrProvince="[REDACTED]" postalCode="[REDACTED]" country="[REDACTED]" default="true" active="true" />
      </h:addresses>
      <h:names>
        <h:name nameCode="PRFR" firstName="[REDACTED]" lastName="[REDACTED]" default="true"
          active="true" />
      </h:names>
      <h:phones>
        <h:phone phoneType="WRK" phoneNumber="[REDACTED]" default="true" active="true" />
      </h:phones>
      <h:emails>
        <h:email emailType="WRK" emailAddress="[REDACTED]" default="true"
          active="true" />
      </h:emails>
    </h:record>
    <h:record principalId="[REDACTED]" principalName="[REDACTED]" active="true">
      <h:affiliations>
        <h:affiliation affiliationType="[REDACTED]" campus="[REDACTED]" default="true" active="true">
          <h:employment employeeStatus="[REDACTED]" employeeType="[REDACTED]" baseSalaryAmount="[REDACTED]"
            primaryDepartment="[REDACTED]" employeeId="[REDACTED]" />
        </h:affiliation>
      </h:affiliations>
      <h:addresses>
        <h:address addressTypeCode="WRK" addressLine1="[REDACTED]" city="[REDACTED]"
          stateOrProvince="[REDACTED]" postalCode="[REDACTED]" country="[REDACTED]" default="true" active="true" />
      </h:addresses>
      <h:names>
        <h:name nameCode="PRFR" firstName="[REDACTED]" lastName="[REDACTED]" default="true"
          active="true" />
      </h:names>
      <h:phones>
        <h:phone phoneType="WRK" phoneNumber="[REDACTED]" default="true" active="true" />
      </h:phones>
      <h:emails>
        <h:email emailType="WRK" emailAddress="[REDACTED]" default="true"
          active="true" />
      </h:emails>
    </h:record>
  </h:records>
</hrmanifest>

谢谢!

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    尝试在所有元素上使用您绑定到名称空间的前缀,例如xsl:for-each select="h:hrmanifest/h:records/h:record" 似乎所有元素都在该命名空间中,尽管有点奇怪,部分带有前缀,部分在默认命名空间中。但是您的 XSLT 1 需要始终使用绑定到该名称空间的前缀。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-30
      • 2012-10-11
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      相关资源
      最近更新 更多