2014-09-11 2 views
0

나는 XML과 함께 작업하고 있습니다. 난 결과가 추가 문자가 포함 된 변환 적용하고 난 후변형은 여분의 데이터를 반환합니다

내 XML

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" 
href="file:///C:/Documents%20and%20Settings/Administrator/My%20Documents/Test/XsltModelo.xslt"?> 
<nyfile> 
    <HourNow>20140820230732</HourNow> 
    <Customer> 
     <ReportType>102,0x00000066</ReportType> 
     <BusinessDate>20140820</BusinessDate> 
     <Mix> 
     <ProductName>noname</ProductName> 
     <FamilyGroup>6</FamilyGroup> 
    </Mix> 
    </Customer> 
</nyfile> 

입니다

하고 그것에게 XSLT

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" 
exclude-result-prefixes="xs fn"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

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

    <xsl:template match="Mix"> 
     <item> 
      <BusinessDate><xsl:value-of select="../BusinessDate" /></BusinessDate> 
      <ProductName><xsl:value-of select="ProductName" /></ProductName> 
     </item> 
    </xsl:template> 

</xsl:stylesheet> 

변환을 적용 이유를 잘 모릅니다 때 문제는

XML 결과에 여분의 문자가 포함되어 있습니다.20x0000006620140820, 누군가가 빛을 보여줄 수 있습니까?

<?xml version="1.0" encoding="UTF-8"?> 
<Items>2,0x0000006620140820 
<item> 
    <BusinessDate>20140820</BusinessDate> 
    <ProductName>noname</ProductName> 
</item> 

답변

0

당신 만 Mix 요소에 대한 템플릿을 정의하지만, 당신이 아래로 nyfile에서 모든 템플릿을 적용하고 있습니다. 따라서 Mix을 제외한 모든 항목은 기본 템플릿 규칙에 따라 처리됩니다.이 템플릿 규칙은 요소를 반복하지만 텍스트 노드 만 출력합니다. 당신은 단지 Mix 섹션을 처리하려면

, 단순히 단지를 선택

<xsl:template match="/"> 
    <Items> 
     <xsl:apply-templates select="nyfile/Customer/Mix"/>  
    </Items> 
</xsl:template> 
+0

덕분에 많이. 그러나 하나의 문제가 존재합니다 고객이 변수가 존재할 수 있습니다 Customer, Customer1, customer2, customer3. 선택에서 어떻게 "nyfile/Customer */Mix"를 설정할 수 있습니까? –

관련 문제