Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 275193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:43:34+00:00 2026-05-12T00:43:34+00:00

Using this file as source, I have a situation where I need to retrieve

  • 0

Using this file as source, I have a situation where I need to retrieve an element from either the local source file or a related one noted in the imports. The type value uses a colon to separate the two values – substring-before(@type, ‘:’) tells me which file to reference; substring-after(@type, ‘:’) is the name of the element in the file I need to copy & iterate over its contents in the same fashion.

Example: I want the xs:complexType where the name is “PersonType”, so I use the copy-of to grab it and its children. The next step is to look at those children – for those that are xs:element, I want to retrieve the element referenced in the type value (“AcRec:HighSchoolType”). The “AcRec” tells me which xsd I need to use, so I know I’ll find something in that xsd where the name value is “HighSchoolType”. Looking at the AcRec xsd, I know that “HighSchoolType” is an xs:complexType (which I already have a template defined to handle) so I should see the output.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:core="urn:org:pesc:core:CoreMain:v1.2.0" xmlns:AcRec="urn:org:pesc:sector:AcademicRecord:v1.1.0">
    <xsl:apply-templates select="//xs:complexType[@name='PersonType']" />       
</xs:schema>
</xsl:template> 

<xsl:template match="xs:complexType">
    <xsl:copy>
        <xsl:copy-of select="node()[not(xs:annotation | xs:restriction)]|@*"/>
    </xsl:copy>
    <xsl:apply-templates select=".//xs:element" />
</xsl:template>

<xsl:template match="xs:simpleType">
    <xsl:copy>
        <xsl:copy-of select="node()|@*"/>
    </xsl:copy>
</xsl:template> 

<xsl:template match="xs:element">
    <xsl:choose>
        <xsl:when test="substring-before(@type, ':') = 'AcRec'">
            <xsl:text>AcRec</xsl:text>
            <xsl:apply-templates select="document('[local file path]AcademicRecord_v1.3.0.xsd')//*[@name=substring-after(@type, ':')]" />
        </xsl:when>                     
    </xsl:choose>
</xsl:template>

Desired output would look like:

<xs:complexType name="PersonType">
  <xs:sequence>
    <xs:element name="HighSchool" type="AcRec:HighSchoolType" minOccurs="0">
  </xs:sequence>
</xs:complexType>
<xs:complexType name="HighSchoolType">
  <xs:sequence>
    <xs:element name="OrganizationName" type="core:OrganizationNameType"/>
    <xs:group ref="core:OrganizationIDGroup" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>

What am I missing about looking within the document when I successfully enter the xsl:when? The xsl:text tells me I’m in, but the subsequent line returns no output.

Additionally, how do I exclude xs:annotation and xs:restriction elements from appearing when copying the xs:complextType & xs:simpleType elements? I haven’t been able to get the examples mentioned on the dpawson site to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:43:34+00:00Added an answer on May 12, 2026 at 12:43 am

    The issue was:

    <xsl:apply-templates select="document('[local file path]AcademicRecord_v1.3.0.xsd')//*[@name=substring-after(@type, ':')]" />
    

    …should be:

    <xsl:variable name="name" select="substring-after(@type, ':')" />
    <xsl:apply-templates select="document('[local file path]AcademicRecord_v1.3.0.xsd')//*[@name=$name]" />
    

    ScottSEA – you were correct when you said it was comparing based on:

    <element name="text" type="some:text"/>
    

    What happens is that there is a context switch involved in the processing of that XPath expression. When you say //*[@name=substring-after(@type, ‘:’)], you say “apply this template to those elements in the XSD document referenced, that have both a @name and a @type attribute, and whose @name is equal to substring-after ‘:’ of THEIR @type. Whereas, if you use a variable, you of course get the substring-after from the current document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 156k
  • Answers 156k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just looking at the right-hand side: are you missing a… May 12, 2026 at 10:57 am
  • Editorial Team
    Editorial Team added an answer A solution that works: Wrap the part of the document… May 12, 2026 at 10:57 am
  • Editorial Team
    Editorial Team added an answer You'll just want to do something like: $(document).ready(function() { $.get('/my/controller',… May 12, 2026 at 10:57 am

Related Questions

I've had success with LuaSocket 's TCP facility, but I'm having trouble with its
I was curious as to what other shops are doing regarding base application frameworks?
I'm looking for some feedback on the advantages and disadvantages of the methods available
I am running into an issue with a FileSystemWatcher when multiple files are placed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.