Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Select value using keys

From: "andrew welch" <andrew.j.welch@--------->
To:
Date: 3/4/2006 4:59:00 PM
On 3/4/06, geoff hopkins <geoffhopkins123@xxxxxxxxx> wrote:
> I did but got no reply....
>
> Date: Thu, 2 Mar 2006 23:40:20 -0800 (PST)
> From: "geoff hopkins" <geoffhopkins123@xxxxxxxxx>
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Select value from document -T2
>
> Take2.
>
> Below is a example of an input xml basically have to
> change the format to that below.  So when START is
> found start reading and stop reading when STOP is
> found.  Have sorted this out ok!
>
> The problem I have is getting the value which is
> outside of the START and STOP tags @doc it is uniquely
> identified in the document as having 'Name:' at the
> start of the text within the node (would prefer it to
> search for first instance of this text)
>
> I can't share the true xml doc for data protection
> issues.
>
> Thanks. Geoff
>
> Example of input doc.
>
> <root>
> <a>sdfsdfsd</a>
> <a>dsfssdf</a>
> <a>Name: DOC_ID1</a>
> <a>iuhs</a>
> <a>sdfsdf</a>
> <a>sdfsd</a>
> <a>START</a>
> <a>A1,A2</a>
> <a>A3,A4</a>
> <a>A5,A6</a>
> <a>A7,A8</a>
> <a>STOP</a>
> <a>sdfsdfds</a>
> <a>sdfsdfsd</a>
> </root>
>
> Example of output:
> <root>
> <doc>
> <relationship parent="A1" child="A2" doc="DOC_ID1"/>
> <relationship parent="A3" child="A4" doc="DOC_ID1"/>
> <relationship parent="A5" child="A6" doc="DOC_ID1"/>
> <relationship parent="A7" child="A8" doc="DOC_ID1"/>
> </doc>
> </root>



<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="root">
  <root>
    <doc>
      <xsl:apply-templates select="a[preceding-sibling::a[. = 'START']]
                                    [following-sibling::a[. = 'STOP']]"/>
	</doc>
  </root>
</xsl:template>

<xsl:template match="a">
  <relationship parent="{substring-before(., ',')}"
     child="{substring-after(., ',')}"
     doc="{substring-after(../a[contains(., 'Name: ')], 'Name: ')}"/>
</xsl:template>
</xsl:stylesheet>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent