[Home] [By Thread] [By Date] [Recent Entries]
Hi,
I have been trying the code, and the output it's not that I expect because the tag subunit is identet inside another subunit like this </sub-sub-subunit> </sub-subunit> </sub-subunit> </sub-subunit> </sub-subunit> </sub-subunit> </sub-subunit> And there are duplicated nodes But the use of the key to mark set of block is very interesting. Thank you. 2006/7/26, Albert Juhi <albertjuhe@xxxxxxxxx>: Hi,self::sub-sub-subunit)]" or self::sub-sub-subunit][1]> use="generate-id( > (parent::unit | > preceding-sibling::* > [self::subunit or self::sub-subunit generate-id(.))"/>
-->> </xsl:copy> > </xsl:template> > > </xsl:stylesheet> > > Albert Juhi wrote: > > Hi David, > > > > The last week an amazin brown arrive me, the problem is the same: > > I have this xml: > > > > <modul> > > <unit id="1"> > > <subunit>Rupturas</subunit> > > <sub-subunit>sistema </sub-subunit> > > <sub-subunit>incertidumbre</sub-subunit> > > <subunit>Megatendencias</subunit> > > <sub-subunit>Caracterizacisn</sub-subunit> > > <sub-sub-subunit>1.2.1.1.</sub-sub-subunit> > > <p>Text 1211</p> > > <param>Text 2 1211</param> > > <sub-sub-subunit>1.2.1.2.</sub-sub-subunit> > > <sub-sub-subunit>1.2.1.3.</sub-sub-subunit> > > <sub-subunit>Vectores</sub-subunit> > > <sub-sub-subunit>1.2.2.1.</sub-sub-subunit> > > <sub-sub-subunit>1.2.2.2.</sub-sub-subunit> > > <sub-sub-subunit>1.2.2.3.</sub-sub-subunit> > > <subunit>Perspectivas</subunit> > > <sub-subunit>Ideologmas</sub-subunit> > > <sub-sub-subunit>1.3.1.1.</sub-sub-subunit> > > <sub-sub-subunit>1.3.1.2.</sub-sub-subunit> > > <sub-subunit>controversia</sub-subunit> > > <sub-sub-subunit>1.3.2.1.</sub-sub-subunit> > > <sub-sub-subunit>1.3.2.2.</sub-sub-subunit> > > </unit> > > <unit id="2"> > > <p>Desafmos sociolaboral</p> > > <subunit>Cantidad</subunit> > > <p>Text Cantidad</p> > > <sub-subunit>riqueza</sub-subunit> > > <sub-subunit>paramso</sub-subunit> > > <sub-subunit>materia</sub-subunit> > > <sub-subunit>panorama a las perspectivas</sub-subunit> > > <subunit>Calidad</subunit> > > <sub-subunit>Polarizacisn</sub-subunit> > > <sub-subunit>La cara</sub-subunit> > > <sub-subunit>La cruz</sub-subunit> > > <sub-subunit>Precarizacisn</sub-subunit> > > <subunit>experiencia</subunit> > > <sub-subunit>Ejes</sub-subunit> > > <sub-subunit>Condiciones</sub-subunit> > > <sub-sub-subunit>2.3.2.1.</sub-sub-subunit> > > <sub-sub-subunit>2.3.2.2.</sub-sub-subunit> > > <sub-sub-subunit>2.3.2.3.</sub-sub-subunit> > > <subunit>paradigma</subunit> > > <sub-subunit>civilizacisn</sub-subunit> > > <sub-subunit>emplemsmo</sub-subunit> > > <sub-subunit>Agenda</sub-subunit> > > </unit> > > </modul> > > > > And I have to convert in a hierarchial xml structure into the unit > > tag, with this conditions: > > - Between tag can exists another tags, this tags belongs to the > > preceding-sibling. > > - The hierarchi is: unit, subunit,sub-subunit and sub-sub-subunit. > > > > Result file and solution: > > > > <modul> > > <unit id="1"> > > <subunit> > > <title>Rupturas</title> > > <sub-subunit> > > <title>sistema </title> > > </sub-subunit> > > <sub-subunit> > > <title>incertidumbre</title> > > </sub-subunit> > > </subunit> > > <subunit> > > <title>Megatendencias</title> > > <sub-subunit> > > <title>Caracterizacisn</title> > > <sub-sub-subunit> > > <title>1.2.1.1.</title> > > <p>Text 1211</p> > > <param>Text 2 1211</param> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>1.2.1.2.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>1.2.1.3.</title> > > </sub-sub-subunit> > > </sub-subunit> > > <sub-subunit> > > <title>Vectores</title> > > <sub-sub-subunit> > > <title>1.2.2.1.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>1.2.2.2.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>1.2.2.3.</title> > > </sub-sub-subunit> > > </sub-subunit> > > </subunit> > > <subunit> > > <title>Perspectivas</title> > > <sub-subunit> > > <title>Ideologmas</title> > > <sub-sub-subunit> > > <title>1.3.1.1.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>1.3.1.2.</title> > > </sub-sub-subunit> > > </sub-subunit> > > <sub-subunit> > > <title>controversia</title> > > <sub-sub-subunit> > > <title>1.3.2.1.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>1.3.2.2.</title> > > </sub-sub-subunit> > > </sub-subunit> > > </subunit> > > </unit> > > <unit id="2"> > > <p>Desafmos sociolaboral</p> > > <subunit> > > <title>Cantidad</title> > > <p>Text Cantidad</p> > > <sub-subunit> > > <title>riqueza</title> > > </sub-subunit> > > <sub-subunit> > > <title>paramso</title> > > </sub-subunit> > > <sub-subunit> > > <title>materia</title> > > </sub-subunit> > > <sub-subunit> > > <title>panorama a las perspectivas</title> > > </sub-subunit> > > </subunit> > > <subunit> > > <title>Calidad</title> > > <sub-subunit> > > <title>Polarizacisn</title> > > </sub-subunit> > > <sub-subunit> > > <title>La cara</title> > > </sub-subunit> > > <sub-subunit> > > <title>La cruz</title> > > </sub-subunit> > > <sub-subunit> > > <title>Precarizacisn</title> > > </sub-subunit> > > </subunit> > > <subunit> > > <title>experiencia</title> > > <sub-subunit> > > <title>Ejes</title> > > </sub-subunit> > > <sub-subunit> > > <title>Condiciones</title> > > <sub-sub-subunit> > > <title>2.3.2.1.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>2.3.2.2.</title> > > </sub-sub-subunit> > > <sub-sub-subunit> > > <title>2.3.2.3.</title> > > </sub-sub-subunit> > > </sub-subunit> > > </subunit> > > <subunit> > > <title>paradigma</title> > > <sub-subunit> > > <title>civilizacisn</title> > > </sub-subunit> > > <sub-subunit> > > <title>emplemsmo</title> > > </sub-subunit> > > <sub-subunit> > > <title>Agenda</title> > > </sub-subunit> > > </subunit> > > </unit> > > </modul> > > > > This is my solution: > > > > <xsl:template match="modul"> > > <xsl:copy> > > <xsl:copy-of select="@*"/> > > <xsl:apply-templates/> > > </xsl:copy> > > </xsl:template> > > > > <xsl:template match="unit"> > > <xsl:copy> > > <xsl:copy-of select="@*"/> > > <xsl:call-template name="process-node"> > > <xsl:with-param name="node-father" select="name()"/> > > </xsl:call-template> > > </xsl:copy> > > </xsl:template> > > > > <!-- Copy elements --> > > <xsl:template match="*"> > > <xsl:copy> > > <xsl:copy-of select="@*"/> > > <xsl:apply-templates/> > > </xsl:copy> > > </xsl:template> > > > > <!-- > > Test if an element match with the final block using generate-id select="$next-element"/>> > <xsl:template name="get-block"> > > <xsl:param name="context" select="."/> > > <xsl:param name="target"/> > > > > <xsl:if test="generate-id($context)!=$target"> > > <xsl:apply-templates select="$context" mode="copia"/> > > <xsl:variable name="next-element" > > select="$context/following-sibling::*[1]"/> > > <xsl:if test="$next-element"> > > <xsl:call-template name="get-block"> > > <xsl:with-param name="context" select="name($context)"/>> > <xsl:with-param name="target" select="$target"/> > > </xsl:call-template> > > </xsl:if> > > </xsl:if> > > > > </xsl:template> > > > > <!-- > > Find a subunit tag > > --> > > <xsl:template name="process-node"> > > <xsl:param name="context" select="*[1]"/> > > <xsl:param name="node-father"/> > > > > <xsl:choose> > > <xsl:when test="$context[self::unit or self::subunit or > > self::sub-subunit or self::sub-sub-subunit]"> > > <xsl:variable name="node-type" select="$node-type"/>
father,> > </xsl:call-template> > > </xsl:variable> > > > > <!-- Test if are the same type and have the same > > for > > continuing processing --> > > <xsl:if test="$seguent-node and > > name($seguent-node)=$node-type and > > (generate-id($seguent-node/preceding-sibling::*[name()=$fathers-name][1])=gen erate-id($context/preceding-sibling::*[name()=$fathers-name][1]))"> or
> > self::sub-subunit or self::sub-sub-subunit]"> > > <xsl:call-template name="process-node"> > > <xsl:with-param name="context" > > select="$context"/> > > </xsl:call-template> > > </xsl:when> > > <xsl:otherwise> > > <xsl:apply-templates select="$context"/> > > <xsl:call-template name="generate-block"> > > <xsl:with-param name="context" > > select="$context/following-sibling::*[1]"/> > > <xsl:with-param name="node-type" > > select="$node-type"/> > > </xsl:call-template> > > </xsl:otherwise> > > </xsl:choose> > > </xsl:if> > > </xsl:if> > > > > </xsl:template> > > > > <!-- Sets the hierarchial order --> > > <xsl:template name="get-ordre-unitat"> > > <xsl:param name="unitat"/> > > > > <xsl:choose> > > <xsl:when test="$unitat='unit'"> > > <xsl:value-of select="'*unit*'"/> > > </xsl:when> > > <xsl:when test="$unitat='subunit'"> > > <xsl:value-of select="'*unit*subunit*'"/> > > </xsl:when> > > <xsl:when test="$unitat='sub-subunit'"> > > <xsl:value-of select="'*unit*subunit*sub-subunit*'"/> > > </xsl:when> > > <xsl:when test="$unitat='sub-sub-subunit'"> > > <xsl:value-of > > select="'*unit*subunit*sub-subunit*sub-sub-subunit*'"/> > > </xsl:when> > > </xsl:choose> > > > > </xsl:template> > > > > <!-- Retorna pare --> > > <xsl:template name="get-pare"> > > <xsl:param name="unitat"/> > > > > <xsl:choose> > > <xsl:when test="$unitat='unit'"> > > <xsl:value-of select="''"/> > > </xsl:when> > > <xsl:when test="$unitat='subunit'"> > > <xsl:value-of select="'unit'"/> > > </xsl:when> > > <xsl:when test="$unitat='sub-subunit'"> > > <xsl:value-of select="'subunit'"/> > > </xsl:when> > > <xsl:when test="$unitat='sub-sub-subunit'"> > > <xsl:value-of select="'sub-subunit'"/> > > </xsl:when> > > </xsl:choose> > > > > </xsl:template>
|

Cart



