Last modified: 2014-06-23 13:47:46 UTC
By design, Cite does not allow a <ref> to appear within another <ref>. (This is probably a result of parser design and concerns over maintaining the integrity of Cite's internal data stack.) However, clever Wikipedians realized that one can use #tag to avoid Cite's design limitations and create functional nested references such as: AAA {{#tag:ref| BBB <ref> CCC </ref> }} (See also: Bug 16330) Recently, Cite was expanded to allow reference content to be defined within a references block, i.e. Foo <ref name="bar"/> <references> <ref name="bar">blah blah</ref> </references> While most references work fine in this context, the #tag based nested ref constructions universally fail when moved inside <references>. Depending on the number and order of #tag calls used and the depth of the stack the result will either be an uninformative error message or a misnumbered reference list. The solution to this is probably to create an implementation that generically supports nested refs. (Part of the problem is that Cite was not intended to allow for nested refs at all and though the #tag based hack worked previously because of quirks in parser behavior, the same call structure doesn't work when moved inside the references block.) The "right" way to do this is probably to restructure Cite's internal data stack and change the way the evaluation of references are hooked into the parser. I will probably implement this myself eventually, though probably not for some months.
An obvious solution to this problem is to use {{#tag:references|...}} construct.
(In reply to comment #1) > An obvious solution to this problem is to use {{#tag:references|...}} > construct. > Apparently one can define a nested ref inside a #tag:references as long as both the portions of the nest are also defined by #tag. Based on an example by Ruslik_Zero: AAAA<ref name="note1" group="note" /> == notes == {{#tag:references| {{#tag:ref|foo{{#tag:ref|inside ref}}bar|group="note"|name="note1"}} |group="note"}} == references == <references /> Frankly, I'm surprised that even that works, but it will fail if any of those three #tag calls is replaced by a normal invocation. Hence I would say this is a rather fragile work around.
I suspect this is the same issue that causes problems with #tag:ref in list defined references. A single use works, but more than one results in Cite error: <ref> tag defined in <references> has no name attribute. Example: <ref group=Note name=a /> <ref group=Note name=b /> <ref group=Note name=c /> ;Notes {{reflist|group=Note|refs= {{#tag:ref|Note1<ref>ref1</ref>|name=a|group=Note}} {{#tag:ref|Note2<ref>ref2</ref>|name=b|group=Note}} {{#tag:ref|Note3<ref>ref3</ref>|name=c|group=Note}} }} ;References {{reflist}} Nesting #tag:ref does not work either: {{#tag:ref|Note1{{#tag:ref|ref1}}|name=a|group=Note}}
Also see bug 22635
*** Bug 22300 has been marked as a duplicate of this bug. ***
A reflist containing both a plain ref tag and a "#tag:" ref tag with a nested ref tag in it works if the ref-in-a-ref is listed before the plain ref, and doesn't work if the ref-in-a-ref is listed after the plain ref (demo here http://en.wikipedia.org/wiki/User:Dan_Pelleg/Sandbox/Nested_refs): This works: text<ref name=n1 group=nested_first/> text<ref name=n2 group=nested_first/>. ;Reflist, nested ref listed first:{{reflist|group=nested_first|refs= {{#tag:ref|With nested reference<ref>content of nested reference</ref>|name=n1|group=nested_first}} <ref name=n2 group=nested_first>With no nested reference</ref> }} ;Nested refs: {{reflist}} This not: text<ref name=n3 group=nested_second/> text<ref name=n4 group=nested_second/>. ;Reflist, nested ref listed second:{{reflist|group=nested_second|refs= <ref name=n3 group=nested_second>With no nested reference</ref> {{#tag:ref|With nested reference<ref>content of nested reference</ref>|name=n4|group=nested_second}} }} ;Nested refs: {{reflist}}
Here is the working sample from above without templates. Placing <ref name=n2> first throws a "Cite error references no text" and a "Cite error references no key". Using #tag:ref more than once in the list throws the errors. **** text<ref name=n1 group=nested_first/> text<ref name=n2 group=nested_first/>. '''Notes''' {{#tag:references| {{#tag:ref|With nested reference<ref>content of nested reference</ref>|name=n1}} <ref name=n2>With no nested reference</ref> |group=nested_first}} '''References''' <references /> **** I consider this the most egregious issue with cite.php. The inability to easily add a reference to an explanatory note using cite.php has caused the creation and retention of multiple templates for this purpose. In use, most of these templates create duplicate ids, thus rendering invalid HTML and bad in-page linking. The simplest fix from the user standpoint would be to allow <ref> tags to nest, while allowing the #tag:ref hack to still work. Note that many uses of #tag:ref have multiple embedded <refs>s. If we have to add new syntax, then we can deal with it. There is no expectation of multiple nesting, i.e. stuffing a #tag:ref inside a #tag:ref.