如何使多记录连接显示在主要部分
How to make multi record join show up in main section
这是出来的文件:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<ns1:getDocumentByKeyResponse xmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Document xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<Attributes>
<Attribute name="count">1</Attribute>
<Attribute name="duration">0:00:00.102</Attribute>
<Attribute name="entity">Requisition</Attribute>
<Attribute name="mode">T-XML</Attribute>
<Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute>
</Attributes>
<Content>
<ExportTXML xmlns:e="http://www.taleo.com/ws/tee800/2009/01" xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<e:Requisition>
<e:ContestNumber>15000005</e:ContestNumber>
<e:JobInformation>
<e:JobInformation>
<e:OtherLocations>
<e:Location>
<e:ZipCode>77002</e:ZipCode>
</e:Location>
<e:Location>
<e:ZipCode>77050</e:ZipCode>
</e:Location>
</e:OtherLocations>
<e:PrimaryLocation>
<e:Location>
<e:ZipCode>77003</e:ZipCode>
</e:Location>
</e:PrimaryLocation>
</e:JobInformation>
</e:JobInformation>
</e:Requisition>
</ExportTXML>
</Content>
</Document>
</ns1:getDocumentByKeyResponse>
</soapenv:Body>
</soapenv:Envelope>
我需要它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<source>
<job>
<job_id>
<![CDATA[15000005]]>
</job_id>
<location_zipcode>
<![CDATA[77002]]>
<![CDATA[77050]]>
<![CDATA[77003]]>
</location_zipcode>
</job>
</source>
我当前的 xsl 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:e="http://www.taleo.com/ws/tee800/2009/01" xmlns:fct="http://www.taleo.com/xsl_functions" exclude-result-prefixes="e fct">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" cdata-section-elements="job_id location_zipcode other_location_zipcode"/>
<xsl:param name="OUTBOUND_FOLDER"/>
<xsl:template match="/">
<source>
<xsl:apply-templates select="//e:Requisition"/>
</source>
</xsl:template>
<xsl:template match="e:Requisition">
<xsl:variable name="location_zipcode" select="e:JobInformation/e:JobInformation/e:PrimaryLocation/e:Location/e:NetworkLocation/e:NetworkLocation/e:ZipCode"/>
<xsl:variable name="other_location_zipcode" select="e:JobInformation/e:JobInformation/e:OtherLocation/e:Location/e:NetworkLocation/e:NetworkLocation/e:ZipCode"/>
<xsl:variable name="job_id" select="e:ContestNumber"/>
<job>
<job_id>
<xsl:value-of select="$job_id"/>
</job_id>
<location_zipcode>
<xsl:value-of select="$location_zipcode"/>
<xsl:value-of select="$other_location_zipcode"/>
</location_zipcode>
</job>
</xsl:template>
</xsl:stylesheet>
此 xslt 在遇到超过 1 个其他位置记录时使其失败。无论有多少,我都需要它来继续拉动。任何想法将不胜感激!
谢谢!
格雷格
以下样式表:
XSLT 1.0 或 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e="http://www.taleo.com/ws/tee800/2009/01"
exclude-result-prefixes="e">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<source>
<xsl:apply-templates select="//e:Requisition"/>
</source>
</xsl:template>
<xsl:template match="e:Requisition">
<job>
<job_id>
<xsl:value-of select="e:ContestNumber"/>
</job_id>
<location_zipcode>
<xsl:for-each select="..//e:Location">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:value-of select="e:ZipCode"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
<xsl:text> </xsl:text>
</xsl:for-each>
</location_zipcode>
</job>
</xsl:template>
</xsl:stylesheet>
当应用于您的示例输入时(清理多余的连字符后!)将 return:
<?xml version="1.0" encoding="UTF-8"?>
<source>
<job>
<job_id>15000005</job_id>
<location_zipcode><![CDATA[77002]]>
<![CDATA[77050]]>
<![CDATA[77003]]>
</location_zipcode>
</job>
</source>
稍微更高效的版本会用完整的、明确的路径替换 //
快捷方式。
我正要添加有关 CDATA 要求的注释,但 Ian Roberts 说我要添加的要好得多:
这是出来的文件:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<ns1:getDocumentByKeyResponse xmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Document xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<Attributes>
<Attribute name="count">1</Attribute>
<Attribute name="duration">0:00:00.102</Attribute>
<Attribute name="entity">Requisition</Attribute>
<Attribute name="mode">T-XML</Attribute>
<Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute>
</Attributes>
<Content>
<ExportTXML xmlns:e="http://www.taleo.com/ws/tee800/2009/01" xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<e:Requisition>
<e:ContestNumber>15000005</e:ContestNumber>
<e:JobInformation>
<e:JobInformation>
<e:OtherLocations>
<e:Location>
<e:ZipCode>77002</e:ZipCode>
</e:Location>
<e:Location>
<e:ZipCode>77050</e:ZipCode>
</e:Location>
</e:OtherLocations>
<e:PrimaryLocation>
<e:Location>
<e:ZipCode>77003</e:ZipCode>
</e:Location>
</e:PrimaryLocation>
</e:JobInformation>
</e:JobInformation>
</e:Requisition>
</ExportTXML>
</Content>
</Document>
</ns1:getDocumentByKeyResponse>
</soapenv:Body>
</soapenv:Envelope>
我需要它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<source>
<job>
<job_id>
<![CDATA[15000005]]>
</job_id>
<location_zipcode>
<![CDATA[77002]]>
<![CDATA[77050]]>
<![CDATA[77003]]>
</location_zipcode>
</job>
</source>
我当前的 xsl 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:e="http://www.taleo.com/ws/tee800/2009/01" xmlns:fct="http://www.taleo.com/xsl_functions" exclude-result-prefixes="e fct">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" cdata-section-elements="job_id location_zipcode other_location_zipcode"/>
<xsl:param name="OUTBOUND_FOLDER"/>
<xsl:template match="/">
<source>
<xsl:apply-templates select="//e:Requisition"/>
</source>
</xsl:template>
<xsl:template match="e:Requisition">
<xsl:variable name="location_zipcode" select="e:JobInformation/e:JobInformation/e:PrimaryLocation/e:Location/e:NetworkLocation/e:NetworkLocation/e:ZipCode"/>
<xsl:variable name="other_location_zipcode" select="e:JobInformation/e:JobInformation/e:OtherLocation/e:Location/e:NetworkLocation/e:NetworkLocation/e:ZipCode"/>
<xsl:variable name="job_id" select="e:ContestNumber"/>
<job>
<job_id>
<xsl:value-of select="$job_id"/>
</job_id>
<location_zipcode>
<xsl:value-of select="$location_zipcode"/>
<xsl:value-of select="$other_location_zipcode"/>
</location_zipcode>
</job>
</xsl:template>
</xsl:stylesheet>
此 xslt 在遇到超过 1 个其他位置记录时使其失败。无论有多少,我都需要它来继续拉动。任何想法将不胜感激! 谢谢! 格雷格
以下样式表:
XSLT 1.0 或 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e="http://www.taleo.com/ws/tee800/2009/01"
exclude-result-prefixes="e">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<source>
<xsl:apply-templates select="//e:Requisition"/>
</source>
</xsl:template>
<xsl:template match="e:Requisition">
<job>
<job_id>
<xsl:value-of select="e:ContestNumber"/>
</job_id>
<location_zipcode>
<xsl:for-each select="..//e:Location">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:value-of select="e:ZipCode"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
<xsl:text> </xsl:text>
</xsl:for-each>
</location_zipcode>
</job>
</xsl:template>
</xsl:stylesheet>
当应用于您的示例输入时(清理多余的连字符后!)将 return:
<?xml version="1.0" encoding="UTF-8"?>
<source>
<job>
<job_id>15000005</job_id>
<location_zipcode><![CDATA[77002]]>
<![CDATA[77050]]>
<![CDATA[77003]]>
</location_zipcode>
</job>
</source>
稍微更高效的版本会用完整的、明确的路径替换 //
快捷方式。
我正要添加有关 CDATA 要求的注释,但 Ian Roberts 说我要添加的要好得多: