How To Reflect XML Source in HTML Output?
Friday, 17 April 2015 · 5 messages · last reply 18 Apr 2015
CG
Quoted text · Eliot Kimber · 3 lines
> I'm use the RESTXQ stuff (very nice) to build a little DITA link > management application. In the service of this I need to sometimes show > the raw XML source of the docs in the repo.
Did you e.g. try to embed the results of
file:read-text() or fn:unparsed-text() ?
But I may have got wrong what you are trying to do. I am not sure what part of the DBA you are talking about.. Do you refer to the result view of the query panel? Maybe you need to specify different serialization parameters (i.e., a different output method) as described in our Wiki.Quoted text · Eliot Kimber · 25 lines
On Fri, Apr 17, 2015 at 6:36 PM, Eliot Kimber <ekimber at contrext.com> wrote: > > I looked at the DBA Web app and it looks like it's using some Javascript > for this and I didn't see any obvious solution in the various BaseX > packages, but I could have missed something. > > I hacked a quick little typeswitch transform just to get something but it > doesn't preserve newlines from the source XML (but I notice the DBA Web > app does, so they must be preserved under the covers). > > Is there a built-in way to generate escaped XML for use in e.g., HTML > <pre> or is there some silly thing I need to do in my typeswitch to make > sure the newlines make it to the HTML result? > > Thanks, > > Eliot > > ————— > Eliot Kimber, Owner > Contrext, LLC > http://contrext.com > > >
CG
Quoted text · Eliot Kimber · 6 lines
> declare function dftest:xmlToHtmlCode($nodes as node()*) as node()* { > <pre>{ > for $node in $nodes > return dftest:nodeToHtml($node) > }</pre> > };
You could serialize the nodes...
let $input := <x/>
return <pre>{ serialize($input) }</pre>...or directly retrieve them from a file:
let $input := fn:unparsed-text(...)
return <pre>{ $input }</pre>
let $text := '<x/>'
return <pre>{ $text }</pre>I see.. This won't work, because the children of the pre node
Quoted text · Eliot Kimber · 67 lines
> > > > That is, I just want to format the XML markup within a <pre> element. > > The result could be arbitrary XML elements, not necessarily a complete > document. > > Cheers, > > E. > > ————— > Eliot Kimber, Owner > Contrext, LLC > http://contrext.com > > > > > On 4/17/15, 12:13 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: > >>> I'm use the RESTXQ stuff (very nice) to build a little DITA link >>> management application. In the service of this I need to sometimes show >>> the raw XML source of the docs in the repo. >> >>Did you e.g. try to embed the results of file:read-text() or >>fn:unparsed-text() ? >> >>But I may have got wrong what you are trying to do. I am not sure what >>part of the DBA you are talking about.. Do you refer to the result >>view of the query panel? Maybe you need to specify different >>serialization parameters (i.e., a different output method) as >>described in our Wiki. >> >> >> >>On Fri, Apr 17, 2015 at 6:36 PM, Eliot Kimber <ekimber at contrext.com> >>wrote: >>> >>> I looked at the DBA Web app and it looks like it's using some Javascript >>> for this and I didn't see any obvious solution in the various BaseX >>> packages, but I could have missed something. >>> >>> I hacked a quick little typeswitch transform just to get something but >>>it >>> doesn't preserve newlines from the source XML (but I notice the DBA Web >>> app does, so they must be preserved under the covers). >>> >>> Is there a built-in way to generate escaped XML for use in e.g., HTML >>> <pre> or is there some silly thing I need to do in my typeswitch to make >>> sure the newlines make it to the HTML result? >>> >>> Thanks, >>> >>> Eliot >>> >>> ————— >>> Eliot Kimber, Owner >>> Contrext, LLC >>> http://contrext.com >>> >>> >>> >> > >
EK
Eliot Kimber17 Apr 2015 20:36 #
I'm use the RESTXQ stuff (very nice) to build a little DITA link management application. In the service of this I need to sometimes show the raw XML source of the docs in the repo.
I looked at the DBA Web app and it looks like it's using some Javascript for this and I didn't see any obvious solution in the various BaseX packages, but I could have missed something.
I hacked a quick little typeswitch transform just to get something but it doesn't preserve newlines from the source XML (but I notice the DBA Web app does, so they must be preserved under the covers).
Is there a built-in way to generate escaped XML for use in e.g., HTML <pre> or is there some silly thing I need to do in my typeswitch to make sure the newlines make it to the HTML result?
Thanks,
Eliot
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
EK
I'm doing this in the context of a RESTXQ function that returns an HTML page (that is, I'm reflecting the XML as part of a larger HTML result that I'm synthesizing:
<div class="result">
{
let $map := dftest:testResolveTopicOrMapUri($repo, $branch)
return dftest:xmlToHtmlCode($map)
}
</div>where dftest:xmlToHtmlCode() is:
declare function dftest:xmlToHtmlCode($nodes as node()*) as node()* {
<pre>{
for $node in $nodes
return dftest:nodeToHtml($node)
}</pre>
};That is, I just want to format the XML markup within a <pre> element.
The result could be arbitrary XML elements, not necessarily a complete document.
Cheers,
E.
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
Quoted text · Christian Grün · 44 lines
On 4/17/15, 12:13 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >> I'm use the RESTXQ stuff (very nice) to build a little DITA link >> management application. In the service of this I need to sometimes show >> the raw XML source of the docs in the repo. > >Did you e.g. try to embed the results of file:read-text() or >fn:unparsed-text() ? > >But I may have got wrong what you are trying to do. I am not sure what >part of the DBA you are talking about.. Do you refer to the result >view of the query panel? Maybe you need to specify different >serialization parameters (i.e., a different output method) as >described in our Wiki. > > > >On Fri, Apr 17, 2015 at 6:36 PM, Eliot Kimber <ekimber at contrext.com> >wrote: >> >> I looked at the DBA Web app and it looks like it's using some Javascript >> for this and I didn't see any obvious solution in the various BaseX >> packages, but I could have missed something. >> >> I hacked a quick little typeswitch transform just to get something but >>it >> doesn't preserve newlines from the source XML (but I notice the DBA Web >> app does, so they must be preserved under the covers). >> >> Is there a built-in way to generate escaped XML for use in e.g., HTML >> <pre> or is there some silly thing I need to do in my typeswitch to make >> sure the newlines make it to the HTML result? >> >> Thanks, >> >> Eliot >> >> ————— >> Eliot Kimber, Owner >> Contrext, LLC >> http://contrext.com >> >> >> >
EK
serialize() does just what I want:
<pre>
{
let $map := dftest:testResolveTopicOrMapUri($repo, $branch) return serialize($map)
}
</pre>Cheers,
E.
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
Quoted text · Christian Grün · 100 lines
On 4/17/15, 12:43 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >> declare function dftest:xmlToHtmlCode($nodes as node()*) as node()* { >> <pre>{ >> for $node in $nodes >> return dftest:nodeToHtml($node) >> }</pre> >> }; > >You could serialize the nodes... > > let $input := <x/> > return <pre>{ serialize($input) }</pre> > >...or directly retrieve them from a file: > > let $input := fn:unparsed-text(...) > return <pre>{ $input }</pre> > > > > > >let $text := '<x/>' >return <pre>{ $text }</pre> > >I see.. This won't work, because the children of the pre node > >> >> >> >> That is, I just want to format the XML markup within a <pre> element. >> >> The result could be arbitrary XML elements, not necessarily a complete >> document. >> >> Cheers, >> >> E. >> >> ————— >> Eliot Kimber, Owner >> Contrext, LLC >> http://contrext.com >> >> >> >> >> On 4/17/15, 12:13 PM, "Christian Grün" <christian.gruen at gmail.com> >>wrote: >> >>>> I'm use the RESTXQ stuff (very nice) to build a little DITA link >>>> management application. In the service of this I need to sometimes >>>>show >>>> the raw XML source of the docs in the repo. >>> >>>Did you e.g. try to embed the results of file:read-text() or >>>fn:unparsed-text() ? >>> >>>But I may have got wrong what you are trying to do. I am not sure what >>>part of the DBA you are talking about.. Do you refer to the result >>>view of the query panel? Maybe you need to specify different >>>serialization parameters (i.e., a different output method) as >>>described in our Wiki. >>> >>> >>> >>>On Fri, Apr 17, 2015 at 6:36 PM, Eliot Kimber <ekimber at contrext.com> >>>wrote: >>>> >>>> I looked at the DBA Web app and it looks like it's using some >>>>Javascript >>>> for this and I didn't see any obvious solution in the various BaseX >>>> packages, but I could have missed something. >>>> >>>> I hacked a quick little typeswitch transform just to get something but >>>>it >>>> doesn't preserve newlines from the source XML (but I notice the DBA >>>>Web >>>> app does, so they must be preserved under the covers). >>>> >>>> Is there a built-in way to generate escaped XML for use in e.g., HTML >>>> <pre> or is there some silly thing I need to do in my typeswitch to >>>>make >>>> sure the newlines make it to the HTML result? >>>> >>>> Thanks, >>>> >>>> Eliot >>>> >>>> ————— >>>> Eliot Kimber, Owner >>>> Contrext, LLC >>>> http://contrext.com >>>> >>>> >>>> >>> >> >> >
Written for BaseX 8.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery