2017-05-06 2 views
0

xslt ... 의 변환에 약간 문제가있어 그 작은 문제는 내가 생각하지만 인터넷에서 솔루션을 찾을 수 없습니다. xml 노드에서 숫자 또는 날짜를 선택하려고하면 다른 XML에 표시 할 수 없습니다. 이것은 원래의 코드 1.0XML에서 XML로 XSLT 번호

내가 XSLT 버전을 사용하고 =

<?xml version="1.0" encoding="utf-8"?> 
<ALL_Machines_having_buttons_from_a_Machintype_price_greater9700> 
    <GreaterTypes> 
     <typename>Grant and Sons</typename> 
     <price>984912.41</price> 
     <serialnumber>7</serialnumber> 
     <outputrate>5</outputrate> 
     <purchasebillxml> 
     <purchasebill> 
      <billnumber>345-20-2422</billnumber> 
      <seller> 
       <id>Nienow-Daugherty</id> 
      </seller> 
      <product> 
       <articlenumber>172185964-0</articlenumber> 
       <amount>50359</amount> 
       <price>676833.08</price> 
      </product> 
      <date>2004-01-28</date> 
     </purchasebill> 
     </purchasebillxml> 
     <buttonsname>595027529-2</buttonsname> 
     <colour>Khaki</colour> 
    </GreaterTypes> 
</ALL_Machines_having_buttons_from_a_Machintype_price_greater9700> 

XSL :

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/> 

<xsl:template match="/ALL_Machines_having_buttons_from_a_Machintype_price_greater9700"> 
<humans> 
<xsl:for-each select="GreaterTypes"> 
<human> 
    <firstName><xsl:value-of select="typename"/></firstName> 
    <livingyears><xsl:value-of select="amount"/></livingyears> 
    <alifesince><xsl:value-of select="date"/></alifesince> 
</human> 

</xsl:for-each> 

</humans> 
</xsl:template> 

</xsl:stylesheet> 

내가 무엇을 얻을 :

<humans> 
<human> 
    <firstName>Grant and Sons</firstName> 
    <livingyears/> 
    <alifesince/> 
</human> 
</humans> 
+0

귀하의 XSLT 코드가 작동하지 않는이 XSLT를 사용해보십시오. 먼저 을 제거해야합니다. 그러면 예상대로 작동합니다. – Gerriet

+0

당신은 내가 문제를 보았던 바로 ...이게 내 문제를 설명하기 위해 만든 예제입니다 ... 어떻게 든 제 원래 파일에서 작동하지 않습니다. (나는 왜 그런지 알지 못합니다. –

+1

예제를 간소화하는 것이 좋습니다. 가능하지만 그 문제는 여전히 관심있는 문제를 복제한다는 것을 의미합니다. 이제는 문제가 다시 나타날 때까지 작동하는 단순화 기능이 있으며 원래 부분에 추가 할 수 있습니다. – Gerriet

답변

1

문제는 dateamount이 더 작은 자손이지만 GreaterTypes의 직접 하위가 아니기 때문에 전체 상대 경로를 지정해야한다는 점입니다.

예를 들어, date 위해이 될 것입니다 :

<xsl:value-of select="purchasebillxml/purchasebill/date"/> 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/ALL_Machines_having_buttons_from_a_Machintype_price_greater9700"> 
<humans> 
<xsl:for-each select="GreaterTypes"> 
<human> 
    <firstName><xsl:value-of select="typename"/></firstName> 
    <livingyears><xsl:value-of select="purchasebillxml/purchasebill/product/amount"/></livingyears> 
    <alifesince><xsl:value-of select="purchasebillxml/purchasebill/date"/></alifesince> 
</human> 
</xsl:for-each> 
</humans> 
</xsl:template> 

</xsl:stylesheet> 
+0

대단히 고마워요! :) –

0

추가를 제거하기 additional humans-tag, for-each-loop를 템플릿 매치로 대체 할 것입니다. 이와 같이 :

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/> 

<xsl:template match="/persons"> 
<humans> 
<xsl:apply-templates/> 
</humans> 
</xsl:template> 

<xsl:template match="person"> 
<human> 
    <firstName><xsl:value-of select="name"/></firstName> 
    <livingyears><xsl:value-of select="age"/></livingyears> 
    <alifesince><xsl:value-of select="birthday"/></alifesince> 
</human> 
</xsl:template> 

</xsl:stylesheet> 
0

일반적으로 XSLT는 정상적으로 보입니다.

첫 번째 <humans>을 제거하십시오. 템플릿 외부에 있으며 일치하는 닫는 태그가 없습니다.

코드를 테스트하기 위해 나는 또한 제거했습니다. xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl" (필요 없음).

위의 수정 사항으로 코드를 테스트 한 결과 괜찮습니다. 에서 확인하십시오 http://xsltransform.net/a9Giww

아마 실제 문제는 당신이 게시물에 포함 된 코드 조각의 어디 엔가 숨겨져있을 것입니다. 을 완전히 코드를보십시오.