Subject: Re: [xsl] Name authority and ID/IDREF From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 29 Sep 2009 08:17:11 -0400 |
I am trying to use ID/IDREF to create what amounts to a name authority file within my XML. The goal is to allow one section of the XML to contain commonly used data (such as names of people), and allow the other sections to access that information, and the information contained within, via the ID ref. I'm including an example of what I'm trying to do after my signature.
I'm using XSLT 1.0, though a 2.0 solution would be welcome as well. Apologies: I am definitely a novice, so this may be really simple. I spent a fair amount of time attempting to find discussion of this on the archives of the list, but never really knew what terms would make a good search string, and so could easily have missed the discussion, if it exists. Thanks in advance for any help!
t:\ftemp>type eric.xml <!DOCTYPE test [ <!ELEMENT test (foo*, bar*) > <!ELEMENT foo (testa, testb) > <!ATTLIST foo ID ID #REQUIRED>
<!ELEMENT bar (testc, testd) > <!ATTLIST bar zok IDREFS #REQUIRED> <!ELEMENT testa ( #PCDATA )> <!ELEMENT testb ( #PCDATA )> <!ELEMENT testc ( #PCDATA )> <!ELEMENT testd ( #PCDATA )> ]> <test> <foo ID="ack"> <testa>blah</testa> <testb>blah2</testb> </foo> <foo ID="grr"> <testa>argh</testa> <testb>argh2</testb> </foo>
<bar zok="ack"> <testc>blah3</testc> <testd>blah4</testd> </bar> </test>
t:\ftemp>type eric.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:apply-templates select="//bar"/> </xsl:template>
<xsl:template match="bar"> <xsl:for-each select="id(@zok)/*"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:for-each> <xsl:for-each select="*"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
t:\ftemp>xslt eric.xml eric.xsl blah blah2 blah3 blah4
t:\ftemp>type eric2.xml <test> <foo ID="ack"> <testa>blah</testa> <testb>blah2</testb> </foo> <foo ID="grr"> <testa>argh</testa> <testb>argh2</testb> </foo>
<bar zok="ack"> <testc>blah3</testc> <testd>blah4</testd> </bar> </test>
t:\ftemp>type eric2.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:apply-templates select="//bar"/> </xsl:template>
<xsl:template match="bar"> <xsl:for-each select="key('ids',@zok)/*"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:for-each> <xsl:for-each select="*"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
t:\ftemp>xslt eric2.xml eric2.xsl blah blah2 blah3 blah4
-- Upcoming hands-on code list, UBL, XSLT, XQuery and XSL-FO classes. Interested in other classes? http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Name authority and ID/IDREF, Eric | Thread | [xsl] id attribution in template ma, Trevor Nicholls |
RE: [xsl] id attribution in templat, Michael Kay | Date | RE: [xsl] id attribution in templat, Wendell Piez |
Month |