2014-05-12 6 views
1

노드 이름을 제거하려고하지만 내용을 유지하거나 노드의 내용을 상위 노드로 복사하려고합니다. SSRS에서 XML을 내보내고 보고서 RDL에 XSLT 파일을 첨부했습니다. 나는 내가 가지고있는 xslt와 가까운 sooo 인 것처럼 느낀다. 파일에서 자주 반복되는 노드 '셀'을 제거하려고합니다.XSLT 노드를 제거하고 내용을 유지하십시오.

<ReportSectionAPercentLabel> 
    <Cell> 
     <losPct>0.262158054711246</losPct> 
    </Cell> 
</ReportSectionAPercentLabel> 

는 다음과 같이하려면 :

<ReportSectionAPercentLabel> 
    <losPct>0.262158054711246</losPct> 
</ReportSectionAPercentLabel> 

이것은 XML에서 excert입니다 :

<?xml version="1.0" encoding="UTF8"?> 
<Report xmlns="My_Report" Name="My report"> 
<ReportSectionATablix> 
    <ReportSectionARowGroup_Collection> 
     <ReportSectionARowGroup> 
      <losProvider>Your Enterprise</losProvider> 
      <ReportSectionAColumnGroup_Collection> 
       <ReportSectionAColumnGroup> 
        <ReportSectionAGroupLabel>07</ReportSectionAGroupLabel> 
        <ReportSectionACountLabel> 
         <Cell> 
          <ReportSectionACount>345</ReportSectionACount> 
         </Cell> 
        </ReportSectionACountLabel> 
        <ReportSectionAPercentLabel> 
         <Cell> 
          <losPct>0.262158054711246</losPct> 
         </Cell> 
        </ReportSectionAPercentLabel> 
       </ReportSectionAColumnGroup> 
       <ReportSectionAColumnGroup> 
        <ReportSectionAGroupLabel>814</ReportSectionAGroupLabel> 
        <ReportSectionACountLabel> 
         <Cell> 
          <ReportSectionACount>153</ReportSectionACount> 
         </Cell> 
       </ReportSectionACountLabel> 
       ... 

이는 XSLT이다

나는이합니다. 셀에 대한 Xpath가 잘못 되었습니까?

<xsl:template match="node()|@*" > 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*" /> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="Cell" > 
    <xsl:apply-templates select="*" /> 
</xsl:template> 

답변

3

당신의 접근 방식

올바른 일이지만, 문제는 네임 스페이스 중 하나입니다. (다른 네임 스페이스 선언에 의해 오버라이드 (override)하지 않는 한) 당신의 XML에서, 당신은 기본 네임 스페이스 선언이 해당 요소를 의미

<Report xmlns="My_Report" Name="My report"> 

합니다 (의 xmlns), 및 모든 자손이 그 네임 스페이스에 속한다. 그러나 을 템플릿 일치로 지정한 XSLT에서 요소가 NO 네임 스페이스에 있습니다.이 요소는 네임 스페이스가있는 XML의 과 일치하지 않습니다. 당신이 수, 당신은 XSLT 2.0을 사용한다면, 또는

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:rep="My_Report"> 
    <xsl:template match="node()|@*" > 
     <xsl:copy> 
     <xsl:apply-templates select="node()|@*" /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="rep:Cell" > 
     <xsl:apply-templates select="*" /> 
    </xsl:template> 
</xsl:stylesheet> 

:

이 솔루션은 요소를 일치에 해당 접두어를 접두사로, 너무 XSLT에서 네임 스페이스를 선언하고 사용하는 것입니다 ... 그 기본 네임 스페이스

이것은 또한 일하는 것이 될 수있는 네임 스페이스 접두사없이 XPath 표현이, 가정이 경우 XPath는 기본 - 네임 스페이스를 사용

어떤 이유로, 당신은 당신의 XSLT에서 네임 스페이스 선언을 코딩하지 않도록하고 싶었 경우
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xpath-default-namespace="My_Report"> 
    <xsl:template match="node()|@*" > 
     <xsl:copy> 
     <xsl:apply-templates select="node()|@*" /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="Cell" > 
     <xsl:apply-templates select="*" /> 
    </xsl:template> 
</xsl:stylesheet> 

, 다음에 템플릿 경기를 변경할 수 있습니다 :

<xsl:template match="*[local-name()='Cell']" > 
+0

는 설명 sooo를 감사합니다. A) 네임 스페이스에 대해 이해하지 못했습니다. B) SSRS 출력에 표준 템플릿을 사용하는 대신 각 네임 스페이스를 지정해야합니다. 감사! – BClaydon

관련 문제