<Records count="1">
<Metadata>
<FieldDefinitions>
<FieldDefinition id="25675" name="GrandpaID" alias="GrandpaID" />
<FieldDefinition id="123" name="Father ID" alias="FatherID" />
<FieldDefinition id="1923" name="Son ID" alias="SonID" />
</FieldDefinitions>
</Metadata>
<LevelCounts>
<LevelCount id="1" count="2" />
<LevelCount id="2" count="2" />
<LevelCount id="3" count="3" />
</LevelCounts>
<Record contentId="578859" levelId="1" moduleId="648" parentId="0">
<Record contentId="138286" levelId="2" moduleId="68" parentId="0">
<Record contentId="107826" levelId="3" moduleId="152" parentId="0">
<Field id="1923" type="1">Grandson Record 1</Field>
</Record>
<Record contentId="107830" levelId="3" moduleId="152" parentId="0">
<Field id="1923" type="1">Grandson Record 2</Field>
</Record>
<Field id="123" type="1">Son Record</Field>
</Record>
<Field id="25675" type="6">Grandpa Record</Field>
</Record>
</Records>
나는 위의 XML을 가지고있다. 내가해야할 일은 각 "손자 기록"을보고 각각에 대한 기록을 만드는 것입니다. 즉, 할아버지/아들 아래에있는 각 손자 기록에 대해 할아버지/손/손자 1이 필요하고 할아버지/손자/손자 2에게는 두 번째 사람이 필요합니다. 나는 다음과 같은 XSLT를 사용하여 두 손자 기록을 동시에 제공합니다 .XSL 변환 - 다중 자식 노드 = 다중 관계
XSLT :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name ="fields" select="//Metadata/FieldDefinitions" />
<!--match the root node-->
<xsl:template match="Records">
<ArcherRecords >
<xsl:apply-templates select="Record" />
</ArcherRecords>
</xsl:template>
<!-- match child relationships -->
<xsl:template match="Record">
<xsl:variable name="fieldName" select="translate(@levelId, ': ', '__')" />
<xsl:element name="Relationship_{$fieldName}">
<xsl:apply-templates select="@contentId" />
<xsl:apply-templates select="Field" />
<xsl:apply-templates select="Record" />
</xsl:element>
</xsl:template>
<!--get field name-->
<xsl:template name="getName">
<xsl:param name="fieldId" />
<xsl:choose>
<xsl:when test="$fields/FieldDefinition[@id=$fieldId]">
<xsl:value-of select="$fields/FieldDefinition[@id=$fieldId]/@alias"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Field_'"/>
<xsl:value-of select="translate(@id, ': ', '__')" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
결과 :
이<?xml version="1.0" encoding="UTF-8"?>
<ArcherRecords xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Relationship_1>
<Field_contentId>578859</Field_contentId>
<GrandpaID>Grandpa Record</GrandpaID>
<Relationship_2>
<Field_contentId>138286</Field_contentId>
<FatherID>Son Record</FatherID>
<Relationship_3>
<Field_contentId>107826</Field_contentId>
<SonID>Grandson Record 1</SonID>
</Relationship_3>
<Relationship_3>
<Field_contentId>107830</Field_contentId>
<SonID>Grandson Record 2</SonID>
</Relationship_3>
</Relationship_2>
</Relationship_1>
</ArcherRecords>
이
원하는 결과가 :
<?xml version="1.0" encoding="UTF-8"?>
<ArcherRecords xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Relationship_1>
<Field_contentId>578859</Field_contentId>
<GrandpaID>Grandpa Record</GrandpaID>
<Relationship_2>
<Field_contentId>138286</Field_contentId>
<FatherID>Son Record</FatherID>
<Relationship_3>
<Field_contentId>107826</Field_contentId>
<SonID>Grandson Record 1</SonID>
</Relationship_3>
</Relationship_2>
</Relationship_1>
<Relationship_1>
<Field_contentId>578859</Field_contentId>
<GrandpaID>Grandpa Record</GrandpaID>
<Relationship_2>
<Field_contentId>138286</Field_contentId>
<FatherID>Son Record</FatherID>
<Relationship_3>
<Field_contentId>107830</Field_contentId>
<SonID>Grandson Record 2</SonID>
</Relationship_3>
</Relationship_2>
</Relationship_1>
</ArcherRecords>
이 어떤 도움을 크게 감상 할 수있다!
알려진 내용과 예제는 무엇입니까? 예 : 3 단계 깊이 - 더있을 수 있습니까? + 부모님 아이디에 대해 이전에 물어 보았습니다 - 그들이 틀린 것이 틀림 없습니다. –
3 단계는 최대한 깊게 들어갑니다. 죄송합니다. 새로운 질문을 만드는 것이 좋습니다. 나는 parentID가 정확하다고 믿는다. Record의 contentID 속성에서 나온다. – user1772421
"* 나는 parentID가 맞다고 믿는다. 레코드의 contentID 속성에서 온다. *"나는 contentID = 138286에 parentId = 578859를 갖는 레코드를 기대한다. –