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

Related Questions

I have a .mbm file that I copy to my device using this line
I have a database file that is generated on a PC using Sqlite. This
One source with multiple objects I am using MSVS 2010 and I have a
I'm trying to digitally sign a PDF file using THIS project as an example.
I am using this php code: exec(unrar e file.rar,$ret,$code); and getting an error code
I'm trying to deploy to a slicehost slice using this config/deploy/production.rb file. I'm clueless
i am using a WSDL file to create a the proxy class file, this
I've written this very simple function to replace a file extension using LINQ in
I am using ASP.NET to transmit a .jar file. This code works perfectly on
How can I load an external JavaScript file using a bookmarklet? This would overcome

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.