2014-10-28 4 views
0

xpath 또는 xslt를 사용하여 프로그래밍 할 때는 noobie입니다. 내가 처리 할 지정된 노드 만 선택하려고하고 프로세스에서 각 요소에 대한 폴더를 만듭니다. 여기에 작업 내 테스트 XML 메신저는 다음과 같습니다처리 할 노드를 하나만 선택하십시오.

XML :

<Sandbox> 
    <Unknow name="Unknow"> 
    <Property name="unknow" value="unknow"/> 
    </Unknow> 
    <View name="Object"> 
    <Element name="first" value="1"> 
     <Property name="great" value="10"/> 
     <Element name="detail" value="3"> 
      <Property name="shiny" value="30"/> 
      <Element name="doNot" value="0"> 
       <Property name="non" value="0"/> 
      </Element> 
     </Element> 
    </Element> 
</View> 
<View name="OtherObject"> 
    <Element name="second" value="2"> 
     <Property name="greater" value="20"/> 
     <Element name="detail" value="4"> 
      <Property name="dark" value="40"/> 
      <Element name="doNot" value="0"> 
       <Property name="non" value="0"/> 
      </Element> 
     </Element> 
    </Element> 
    </View> 
</Sandbox> 

XSLT

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:strip-space elements="*"/> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:template match="Sandbox/View[@name='OtherObject']"> 
    <xsl:apply-templates select="//Element"/> 
</xsl:template> 
<xsl:template match="Element"> 
    <xsl:result-document href="{string-join(ancestor-or-self::Element,'/')}/{concat(@name,'_',position())}.xml"> 
     <item> 
      <xsl:copy-of select="."/> 
     </item> 
    </xsl:result-document> 
</xsl:template> 

내가 갖고 싶어 출력은 폴더 구조/객체/처음으로/세부입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 출력 파일을 만들 수 없다는 오류가 나타납니다. 내 xpath doesnt가 ​​맞다는 것을 짐작하는 xpath 사촌에 대한 조언이 있습니까?

<xsl:template match="Sandbox/View[@name='OtherObject']"> 
    <xsl:apply-templates select="//Element"/> 
</xsl:template> 

주셔서 감사합니다

+0

경로에 "doNot"(@name 요소 중 하나)이 포함되지 않습니다. 제외 시키시겠습니까? 또한 첫 번째 템플릿에는 @name ..과 같은 "OtherObject"가 있지만 원하는 폴더 경로에는 "Object"가 있습니다. 어떤 노드를 실제로 처리하고 싶습니까? –

답변

0

당신은 아마 <xsl:result-document href="{string-join(ancestor-or-self::Element,'/')}/{concat(@name,'_',position())}.xml">에 관해서는

<xsl:template match="/"> 
    <xsl:apply-templates select="Sandbox/View[@name='OtherObject']//Element"/> 
</xsl:template> 

는, 어떤 파일 이름은 구성 할 폴더 이름과 정확한 오류 메시지를 게시하고 알려주십시오합니다.

<xsl:result-document href="{string-join(ancestor-or-self::Element,'/')}/{concat(@name,'_',position())}.xml"> 
+0

'href'를 변수에 저장하는 것이 가능하다고 생각합니까? – Artiom

관련 문제