Select only one node to be processed



I'm noobie when it comes to programming with xpath or xslt. Im trying to select only specified node to be processed and in the process create folders for each element. Here's my test xml im working with:


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>


XSLT



<xsl:stylesheet version="2.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<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>


The output i want to have is a folder structure /Object/first/detail. What am i doing wrong? I'm getting an error that i cannot create output file. Do you have any advice on xpath cuz im guessing that my xpath doesnt do i right. Thanks


No comments:

Post a Comment